Getting a .xlsm file to not execute code when being opened with VBA

前端 未结 2 708
醉话见心
醉话见心 2020-12-21 11:08

Have a macro in Excel. Part of that macro opens up other workbooks using Workbooks.Open(Filepath)

Some of the workbooks I\'m opening have (badly done) V

相关标签:
2条回答
  • 2020-12-21 11:44

    AutomationSecurity is likely what you want:

    https://docs.microsoft.com/en-us/office/vba/api/Excel.Application.AutomationSecurity

    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. Note This setting does not disable Microsoft Excel 4.0 macros. If a file that contains Microsoft Excel 4.0 macros is opened programmatically, the user will be prompted to decide whether or not to open the file.

    msoAutomationSecurityLow . Enables all macros. This is the default value when the application is started.

    0 讨论(0)
  • 2020-12-21 11:58

    You can disable the macros for newly opened files, open the workbook, and then re-enable the macros:

    Private Sub OpenWorkBookMacroDisabled(wbPath As String)
        Application.AutomationSecurity = msoAutomationSecurityForceDisable
        Workbooks.Open (wbPath)
        Application.AutomationSecurity = msoAutomationSecurityByUI
    End Sub
    
    0 讨论(0)
提交回复
热议问题