AutomationSecurity Property

Microsoft Word Visual Basic

Show All Show All

AutomationSecurity Property

Returns or sets an MsoAutomationSecurity constant that represents the security setting Microsoft Word uses when programmatically opening files.

MsoAutomationSecurity can be one of these MsoAutomationSecurity constants.

msoAutomationSecurityByUI   Uses the security setting specified in the Security dialog box.
msoAutomationSecurityForceDisable   Disables all macros in all files opened programmatically without showing any security alerts.
msoAutomationSecurityLow   Enables all macros. This is the default value of the property.

expression.AutomationSecurity

expression    Required. An expression that returns one of the objects in the Applies To list.

Remarks

The default setting of the AutomationSecurity property is msoAutomationSecurityLow. Therefore, to avoid changing the users security settings or breaking solutions that rely on the default setting, you should be careful to set this property back to its original setting after programmatically opening a file.

Setting ScreenUpdating to False does not affect alerts and will not affect security warnings. The DisplayAlerts setting will not apply to security warnings. For example, if the user sets DisplayAlerts equal to False and AutomationSecurity to msoAutomationSecurityByUI, while the user is on Medium security level, then there will be security warnings while the macro is running. This allows the macro to trap file open errors, while still showing the security warning if the file open succeeds.

Example

This example changes the setting to disable macros, displays the Open dialog box, and then sets the AutomationSecurity property back to its original setting.

    Sub Security()
    Dim lngAutomation As MsoAutomationSecurity

    With Application
        lngAutomation = .AutomationSecurity
        .AutomationSecurity = msoAutomationSecurityForceDisable
        With .FileDialog(msoFileDialogOpen)
            .Show
            .Execute
        End With
        .AutomationSecurity = lngAutomation
    End With

End Sub