Name

Application.AutomationSecurity [=MsoAutomationSecurity]

Synopsis

Set or returns the macro security setting used when opening Office documents in code. Possible settings are:

msoAutomationSecurityLow

Enable all macros. This is the default.

msoAutomationSecurityByUI

Use the security setting specified in the Security dialog box.

msoAutomationSecurityForceDisable

Disable all without showing any security alerts.

These settings apply only to files opened in code. Files opened by the user apply the settings in the Security dialog box.

The default setting for this property is a security hole created to provide backward compatibility with multifile macros written for earlier versions of Excel. You should close this hole in your own code by setting the property to msoAutomationSecurityByUI before opening files, as shown here:

Sub TestMacroSecurity(  )
    ' Enable macro security on file to open
    Application.AutomationSecurity = msoAutomationSecurityByUI
    With Application.FileDialog(msoFileDialogOpen)
        .AllowMultiSelect = False
        ' Get a file
        .Show
        ' Open it.
        Application.Workbooks.Open .SelectedItems(1)
    End With
End Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.