vba - 使 .xlsm 文件在使用 VBA 打开时不执行代码

标签 vba excel

我在 Excel 中有一个宏。该宏的一部分使用 Workbooks.Open(Filepath) 打开其他工作簿。

我打开的一些工作簿中包含(做得很糟糕的)VBA 代码,这些代码尝试计算 UDF 并严重失败。

如果不诉诸On Error Resume NextOn 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/

相关文章:

excel - 如何在两个Excel工作表之间逐个比较单元格?

regex - 如何使用 vba 正确地重新格式化具有多种变化的尺寸值?

mysql - 计算多个表中每个 ID 的行数

Excel VBA - 如何从列中的每个单元格中删除某种颜色的文本

sql - Postgresql:从 excel 列中插入许多值

excel-formula - 当一系列数字变为负数时确定单元格 ID 的 Excel 公式

vba - Excel 中的 HMAC SHA256 宏

excel - 统计打开的 Excel 工作簿的数量

arrays - 操作数组内的(TRUE、FALSE)值

java - 根据自定义值对 HashMap 进行排序(例如,它是一个名为 DATA 的类)