我在 Excel 中有一个宏。该宏的一部分使用 Workbooks.Open(Filepath)
打开其他工作簿。
我打开的一些工作簿中包含(做得很糟糕的)VBA 代码,这些代码尝试计算 UDF 并严重失败。
如果不诉诸On Error Resume Next
或On Error GoTo
,我该如何说“打开此文件,不要运行任何代码”。
出于可能的安全问题,首先尝试避免让代码执行。我觉得打开这些文件很舒服,而且它们很有可能不会受到损害,但违规行为可能会发生,当我不需要一个漏洞时,为什么要留一个漏洞呢?我也不希望错误消息中断我的代码执行。
搜索网络只是显示我使用shift+open打开文件而不执行代码,这根本不是我想要做的。我正在寻找等效的 VBA 方法。
最佳答案
AutomationSecurity
可能是您想要的:
https://learn.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.
关于vba - 使 .xlsm 文件在使用 VBA 打开时不执行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51888282/