I have a problem that happens on certain machines (seems to be those running Office 365 version 1809), but I have the same version of 365 running on on other machines, and those are fine with precisely the same code.
I need to programmatically open a PowerPoint presentation that is password protected. In itself, just opening a password-protected PowerPoint presentation seems to be more, ahem, challenging compared to the other Office products, but after some experimentation and Googling the issue, this code seems to be the way to do it:
Dim ppt
MsgBox "booting ppt"
Set ppt = CreateObject("powerpoint.application")
ppt.Visible = True
Dim pvw
MsgBox "loading pvw"
Set pvw = ppt.ProtectedViewWindows.Open("C:\Files\pres.pptx", "password")
If pvw Is Nothing Then MsgBox "no pvw" Else MsgBox "got pvw"
pvw.Activate
Set pvw = Nothing
Set ppt = Nothing
MsgBox "end"
Yes, I know, nasty code, but getting VSTO involved or something more strongly-typed doesn't help either, I've just tried to come up with the simplest possible code with the least number of "moving parts" to replicate the problem. I've put the MsgBox calls in so I can see where this fails.
When I try the equivalent using VSTO, I get the following error:
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
I've tried to rule COM interop out, by just putting the above code in as VBA into a .vbs script and running that, but this also fails:
Error: Unspecified error
Code: 80004005
Finally, I've tried just running this directly from within PowerPoint itself via a macro, but that also fails with the following error:
Method 'Open' of object 'ProtectedViewWindows' failed
I simply can't get this to work on an affected machine - to reproduce it, simply create and save a password-protected PowerPoint presentation in pptx format, and amend the path and password in the code above as appropriate, and then run as a macro, or vbs, or via VSTO if you have time on your hands.
I've tried lots of things:
This machine has been bounced between the 32 and 64-bit versions of Office 365 (currently on 32-bit Office 365), it's a 64-bit Windows 7 system.
I've even tried monitoring it via SysInternals' Process Monitor, but nothing seems forthcoming, awash the hundreds of thousands of things that are logged between the message box and the protected open event.
I can see that PowerPoint can read the file, as the protected view window briefly flashes up mentioning the relevant file. If I deliberately mis-spell the filename (to see if it even tries to open it), I get a different error. If I deliberately mis-spell the password, I also get a different error, which does imply that PowerPoint can access and read/decrypt the file. Obviously, I've tried to open the file manually in PowerPoint and manually enter the password, and that works fine.
It really feels like there is something broken deep within PowerPoint itself - almost as though it can open, decrypt, and read the file, and once it's "got" the file, it's going down a final series of tests, and one of those is failing, but it just gives the generic and unhelpful error E_FAIL (0x80004005).
There is nothing "special" about the machine itself, it's not part of a domain/AD, it has no developer tools on it, and nobody has been "playing" with registry permissions or anything like that.
I'm completely at a loss as to why it fails - doing an office installation "repair" seems to make no difference, nor does a complete uninstall/reinstall of Office. I've not tried reloading the OS from scratch, but that's not really an option, this configuration is likely to be encountered somewhere in the "wild", so I'd rather find the root cause.
Any ideas?
Thanks, Nick.
User contributions licensed under CC BY-SA 3.0