NetOfficeFw / NetOffice

🌌 Create add-ins and automation code for Microsoft Office applications.
MIT License
697 stars 143 forks source link

Failed to proceed Method on PowerPoint.Presentation=>Save #341

Closed Offbeatmammal closed 2 years ago

Offbeatmammal commented 2 years ago

I've recently been seeing this error (and obviously the presentation fails to save) happening consistently on two machines (which were working):

presentation.SaveAs(Globals.out_dir + user_name + @"\" + fn + ".pptx", 
                        PpSaveAsFileType.ppSaveAsOpenXMLPresentation);````

Same happens with a presentation.Save()... but saving as PDF works fine, as well as ppSaveAsPresentation (which saves in older .ppt format). ppSaveAsDefault (which is set to the 'current' Presentation) also fails.

anything I should (or shouldn't) be doing, or pointers to track this down?

NetOffice.Exceptions.MethodCOMException (0x80004005): Failed to proceed Method on PowerPoint.Presentation=>Save. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)) --- End of inner exception stack trace --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at NetOffice.Invoker.Method(ICOMObject comObject, String name, Object[] paramsArray) at NetOffice.Invoker.Method(ICOMObject comObject, String name, Object[] paramsArray) at NetOffice.PowerPointApi._Presentation.Save()

jozefizso commented 2 years ago

Hi @Offbeatmammal, you should handle the error when Save() method fails in you application code, eg. by running it again.

Offbeatmammal commented 2 years ago

Hi @Offbeatmammal, you should handle the error when Save() method fails in you application code, eg. by running it again.

repeating save didn't help sadly, so ended up with a very step-by-step debug approach of adding a save after every object change the script was making to the template until I could track down where it was breaking!

looks like the latest powerpoint change has made it a bit more careful about saving pptx's with a zero byte image in - I'm guessing they've tightened up the code to reduce saving corrupted pptx's and it caught a previously non-breaking issue with my code.