Monday, January 30, 2017

Open/save password protected PowerPoint Presentations using VSTO

Although VSTO offers easy ways to save or open password protected Word documents or Excel Workbooks e.g. in pseudocode, Open(docpath, ..., password) or Save(docpath,..., password), it does not offer such options for PowerPoint presentations. However, there is still a way to do it programmatically fairly easily:

To save a presentation with a password:

PowerPoint.Presentation p = Globals.ThisAddIn.Application.Presentations.Add();
p.Password = "whatever";

To open a password protected presentation simply pass the password at the end of the presentation path, when opening it, in this "hackish" way:

PowerPoint.Presentation d = Globals.ThisAddIn.Application.Presentations.Open(FullFilePath + "::whatever::");