AutomationSecurity property
Microsoft Word
Microsoft Word now supports an additional level of security that affects macros that open other Office documents that contain macros.
The setting must be enabled as part of the Microsoft Visual Basic for Applications (VBA) macro code. You can use the
Application.AutomationSecurity property to set the level of security as listed in the following table:
Property | Description |
msoAutomationSecurityForceDisable | Disables the macros in all documents that are opened by previously enabled macros. This setting provides the highest level of security. |
msoAutomationSecurityByUI | Respects the Warn before opening a file that contains macros preference for macros in all documents opened by previously enabled macros. |
msoAutomationSecurityLow | Enables the macros in all document that are opened by previously enabled macros. |
The
Application.AutomationSecurity property interacts with the
Warn before opening a file that contains macros preference in the following ways:
- If the Application.AutomationSecurity property is set to msoAutomationSecurityLow, the user is not prompted to enable macros for documents that were opened by a macro regardless of the setting of the macro warning option. Macros in these documents are automatically enabled.
- If the Application.AutomationSecurity property is set to msoAutomationSecurityForceDisable, the user is not prompted to enable macros for documents that were opened by a macro regardless of the setting of the macro warning option. Macros in these documents are automatically disabled.
Microsoft PowerPoint
Security in Microsoft PowerPoint has been improved when you open a document that contains macros. Additionally, PowerPoint supports an additional level of security that affects macros that open other Office documents that contain macros.
The setting must be enabled as part of the VBA macro code. You can use the
Application.AutomationSecurity property to set the level of security as listed in the following table:
Property | Description |
msoAutomationSecurityForceDisable | Disables the macros in all documents that were opened by previously enabled macros. This setting provides the highest level of security. |
msoAutomationSecurityByUI | Respects the Enable macro virus protection preference for macros in all documents that were opened by previously enabled macros. |
msoAutomationSecurityLow | Enables the macros in all the document that were opened by previously enabled macros. |
The
Application.AutomationSecurity property interacts with the
Enable macro virus protection preference in the following ways:
- If the Application.AutomationSecurity property is set to msoAutomationSecurityLow, the user is not prompted to enable macros for documents that were opened by a macro regardless of the setting of the macro warning option. Macros in these documents are automatically enabled.
- If the Application.AutomationSecurity property is set to msoAutomationSecurityForceDisable, the user is not prompted to enable macros for documents that were opened by a macro regardless of the setting of the macro warning option. Macros in these documents are automatically disabled.
Microsoft Excel
Microsoft Excel now supports an additional level of security that affects macros that open other Office documents that contain macros.
The setting must be enabled as part of the VBA macro code. You can use the
Application.AutomationSecurity property to set the level of security as listed in the following table:
Property | Description |
msoAutomationSecurityForceDisable | Disables the macros in all the documents that were opened by previously enabled macros. This setting provides the highest level of security. |
msoAutomationSecurityByUI | Respects the Warn before opening a file that contains macros preference for macros in all the documents that were opened by previously enabled macros. |
msoAutomationSecurityLow | Enables the macros in all the document that were opened by previously enabled macros. |
The
Application.AutomationSecurity property interacts with the
Warn before opening a file that contains macros preference in the following ways:
- If the Application.AutomationSecurity property is set to msoAutomationSecurityLow, the user is not prompted to enable macros for documents that were opened by a macro regardless of the setting of the macro warning option. Macros in these documents are automatically enabled.
- If the Application.AutomationSecurity property is set to msoAutomationSecurityForceDisable, the user is not prompted to enable macros for documents that were opened by a macro regardless of the setting of the macro warning option. Macros in these documents are automatically disabled.
Sample code
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
Sub Security()
Dim secAutomation As MsoAutomationSecurity
secAutomation = Application.AutomationSecurity
Application.AutomationSecurity = msoAutomationSecurityForceDisable
With Application.FileDialog(msoFileDialogOpen)
.Show
.Execute
End With
Application.AutomationSecurity = secAutomation
End Sub
Implications
If the
Application.AutomationSecurity property is set to
msoAutomationSecurityByUI and the
Warn before opening a file that contains macros preference is selected, you receive a warning dialog box whenever a macro tries to open a file that contains a macro. If you click
Do Not Open to deny this attempt, you receive the following error message.
Run-time error '4198'
Command failed
Additionally, if a macro tries to open a file that contains a macro, the attempt will fail if both of the following conditions are true:
- The Application.AutomationSecurity property option is set to msoAutomationSecurityForceDisable.
- The attempt to open the file is made through an Office API macro. This includes macros that are written in VBA, XLM in Excel, and WordBasic in Word.