Invoke VBA Dim as Outlook.Application not working


I am currently trying to run a VBA code to extract pdf attachments from a .msg file.
The macro works in Excel, but when I try to run it in UiPath using the Invoke VBA method, I get the following error in the “Dim app As Outlook.Application” line:

Why is this error occurring when using the Invoke VBA activity?


This seems a problem with missing Outlook references. If you are trying to execute this VBA script from an excel file you will need to add the Outlook reference, due it is not included by default in excel.

Other way to tackle this (without adding references) would be to use late-binding method. You will need to declare variables as ‘object’ type and then assign its proper type (Outlook.Application):

Dim app as Object
Set app = CreateObject(“Outlook.Application”)

1 Like

Hi @Hisuhong, did you find any solution on your problem? If yes, could you maybe share the code for some help?
I also would like to create an Outlook.Application object and also a NameSpace object, but unfortunately does not really work.
(Other question: do we need to add any imports?)
Thank you!