Execute Macro: "closeExcel" throws error

excel
macro

#1

I have a macro called CloseExcel. it contains simply Application.Close. Obviously I’m looking for a reliable way to close excel when I’m done with it and clicking X isn’t working for me. I’ve called excel macros reliably before so I thought this was a good way but it threw an exception:

Source: Execute macro

Message: Exception from HRESULT: 0x800AC472

Exception Type: ExcelException

UiPath.Excel.ExcelException: Exception from HRESULT: 0x800AC472 —> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800AC472
at Microsoft.Office.Interop.Excel.ApplicationClass.Run(Object Macro, Object Arg1, Object Arg2, Object Arg3, Object Arg4, Object Arg5, Object Arg6, Object Arg7, Object Arg8, Object Arg9, Object Arg10, Object Arg11, Object Arg12, Object Arg13, Object Arg14, Object Arg15, Object Arg16, Object Arg17, Object Arg18, Object Arg19, Object Arg20, Object Arg21, Object Arg22, Object Arg23, Object Arg24, Object Arg25, Object Arg26, Object Arg27, Object Arg28, Object Arg29, Object Arg30)
at UiPath.Excel.WorkbookApplication.RunMacro(String macroName)
— End of inner exception stack trace —
at UiPath.Excel.Activities.ExecuteMacro.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)


#2

I may not understand the need because you should be running Excel activities (including Macros) inside the Excel Application Scope which closes Excel when you exit that scope. Your Application.Close macro may have a hard time when UiPath is waiting to close it itself.

And there is always the Close Application activity and select Excel. :slight_smile:

Hope this helps.


#3

thanks. on another thread someone mentioned the close application activity. I had completely forgotten that one. It is actually too bad, in my opinion, that there isn’t a way to leave excel open at the end of an application scope at least as an option. I can envision many operations that find everything needed for a complicated excel spreadsheet update, do the update, then the user will want to analyze the results. The way it works now you have to reopen the application. Anyway thanks, you might have it the nail on the head with the macro conflicting with the app scope trying to close it.