I have a python script on macOS that opens a .xlsm file and executes a macro, but when I reference my macro on line 1, it opens Excel and prompts me to click "Enable Macros".
我在macOS上有一个python脚本打开一个.xlsm文件并执行一个宏,但是当我在第1行引用我的宏时,它会打开Excel并提示我单击“启用宏”。
At the moment, I have a sleep function so I can click "Enable Macros" manually, but is there a way to program this?
目前,我有一个睡眠功能,所以我可以手动点击“启用宏”,但有没有办法对此进行编程?
1 wb = xw.Book('./filename.xlsm')
2 time.sleep(5)
3 my_macro = wb.macro('some_macro')
4 my_macro()
2 个解决方案
#1
1
Not the best idea but turning off this prompt would help.
不是最好的主意,但关闭此提示会有所帮助。
-
Click the Microsoft Office Button , and then click Excel Options.
单击“Microsoft Office按钮”,然后单击“Excel选项”。
-
Click Trust Center, click Trust Center Settings, and then click Macro Settings.
单击“信任中心”,单击“信任中心设置”,然后单击“宏设置”。
-
Click the option that you want.
单击所需的选项。
#2
0
You might try adding the just created document to the list of trusted documents, which is kept in the registry here:
您可以尝试将刚刚创建的文档添加到受信任文档列表中,该文档保存在注册表中:
Software\Microsoft\Office\16.0\Excel\Security\Trusted Documents\TrustRecords
#1
1
Not the best idea but turning off this prompt would help.
不是最好的主意,但关闭此提示会有所帮助。
-
Click the Microsoft Office Button , and then click Excel Options.
单击“Microsoft Office按钮”,然后单击“Excel选项”。
-
Click Trust Center, click Trust Center Settings, and then click Macro Settings.
单击“信任中心”,单击“信任中心设置”,然后单击“宏设置”。
-
Click the option that you want.
单击所需的选项。
#2
0
You might try adding the just created document to the list of trusted documents, which is kept in the registry here:
您可以尝试将刚刚创建的文档添加到受信任文档列表中,该文档保存在注册表中:
Software\Microsoft\Office\16.0\Excel\Security\Trusted Documents\TrustRecords