Enable outlook macros with VBA

106 Views Asked by At

I was tasked to modify an application built on VBA that is built into the Microsoft Office Outlook app. We recently got an upgrade from office 2016 to office 2021, which is a huge difference in how office operates. In order for our app to work, in the setup vbscript code, we had to enable macros in outlook, otherwise it wouldn't allow them by default and the app wouldn't work. We had a script that does exactly that, but since the upgrade, it seems like the new office ignores that lines of code.

The code that worked for office 2016 but is being ignored:

Dim olApp As Object
Set olApp = Createobject("Outlook.Application")
olApp.Application.AutomationSecurity 1
Dim exportedUIPath As String
Set olApp = Nothing
rem pause
1

There are 1 best solutions below

0
Eugene Astafiev On

The Outlook object model doesn't provide the AutomationSecurity property. Most probably the code was borrowed from Excel where you can find the corresponding property. In case of Outlook you need to set up a group policy or set windows registry keys directly. For example, see Automation Security and Registry setting for changing macro security to "Enable all macros" for more information. Note, in that case Outlook must be restarted to apply new settings.