Let me first describe the problem. I have this application that opens a word document and updates all the fields and then saves the document in another folder. The word document is just used as a template for a report. It is filled with linked content from an excel worksheet. The whole application works, but the problem is that the excel document is password protected. when I update the document fields the application is stopped and word asks for a password.
When you input the password, the program works as advertised, you have to insert it more than once thou, dont really know why. But the program is suppose to work autonomously without user input. Is there a way to give word the password so that it doesnt have to be entered, either via code or in the word document properties.
Below is my current code that does this, its in C#
Microsoft.Office.Interop.Word.Application ap = new Microsoft.Office.Interop.Word.Application();
Document doc = ap.Documents.Open(template, ReadOnly: false, Visible: false);
doc.Activate();
red_debug.AppendText("opening " + template + "\n");
doc.Fields.UpdateSource();
doc.Fields.Update();
red_debug.AppendText("Saving as " + final + "\n");
doc.SaveAs(final, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument);
doc.SaveAs(path + "\\" + name, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF);
red_debug.AppendText("Closing word" + "\n");
doc.Close();
ap.Quit();