问题描述
我试图在不同的工作表上调用一个子文件,但是我有一个运行时错误消息。
I am trying to call a sub on a different worksheet but I got a run time error message.
具体来说,我在这些工作表中有两个工作表和多个VBA子。在VBA项目之一(说workbook1.xlsm)中,我有以下代码:
Specifically, I have two worksheets and multiple VBA sub s in those worksheets. In one of the VBA Project (say workbook1.xlsm), I have the following code:
Sub AnalysisTableMacro()
Workbooks("Python solution macro.xlsm").Activate
Application.Run "Python solution macro.xlsm!.PreparetheTables"
End Sub
但是我收到以下错误。两个工作表上的宏都被启用。在两个工作表中,子模块都在Module1中。
But I got the following error. The macros on both worksheets are enabled. In both worksheets, the subs are in Module1.
我还尝试过应用程序.RunPython解决方案macro.xlsm!Module1.PreparetheTables
但没有工作。
I also tried Application.Run "Python solution macro.xlsm!Module1.PreparetheTables"
but did not work.
任何帮助将不胜感激。
推荐答案
Per ,尝试允许对Visual Basic项目进行编程访问:
Per Microsoft's KB, try allowing programmatic access to the Visual Basic project:
- 点击Microsoft Office按钮,然后单击Excel选项。
- 单击信任中心。
- 单击信任中心设置。
- 单击宏设置。
- 单击以选中对VBA项目对象模型的信任访问复选框。
- 单击确定关闭Excel选项对话框
- 您可能需要关闭并重新打开excel。
- Click the Microsoft Office Button, and then click Excel Options.
- Click Trust Center.
- Click Trust Center Settings.
- Click Macro Settings.
- Click to select the Trust access to the VBA project object model check box.
- Click OK to close the Excel Options dialog box.
- You may need to close and re-open excel.
这篇关于无法运行宏...该工作簿中的宏可能不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!