Outlook API SaveAs ComException

Hi Everyone,

Does anyone use Outlook API within Invoke Code activity to save email as msg message and had the following error?


Dim outApp As Microsoft.Office.Interop.Outlook.Application
outApp = New Microsoft.Office.Interop.Outlook.ApplicationClass()
Dim mailItemInterface As Microsoft.Office.Interop.Outlook._MailItem
Dim mail As Object
mail = outApp.Session.Folders.Item(1).Folders(“Inbox”).Items(1)
mailItemInterface = CType(mail, Microsoft.Office.Interop.Outlook._MailItem)
mailItemInterface.SaveAs(“C:\NewFolder\awdadasd.msg”, Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSG)


An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ----> System.Runtime.InteropServices.COMException: Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
at Microsoft.Office.Interop.Outlook._MailItem.SaveAs(String Path, Object Type)
at UiPathCodeRunner_fddff89e6154429c9e13d928ea536ed2.Run()
— End of inner ExceptionDetail stack trace —
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object providedArgs, ParameterModifier modifiers, CultureInfo culture, String namedParams)
at UiPath.Core.Activities.Workflow.CompilerRunner.Run(Object args)
at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

did you get a chance to save this code as a vbs file and execute… and see if this is working fine or not. If this is working fine… then you can use the same on the vbs file by using start process activity.

Unfortunately not.
It looks like it’s a process architecture problem. Office is x64 but UiPath is x86 so some operations don’t work.

I’m having the following error with vba, probably because parent process (uirobot) produces the child process(vba script) so the running vba script is getting into x86 architecture process which should lead it to run as x86 application

Microsoft Visual Basic for Applications

Run-time error ‘287’:

Application-defined or object-defined error

OK Help

Hi All,

My solution is listed in this thread…


1 Like

thanks a lot :slight_smile:

1 Like