Home » excel » How to click "Enable Macros" when opening Excel using xlwings?

How to click "Enable Macros" when opening Excel using xlwings?

Posted by: admin March 9, 2020 Leave a comment

Questions:

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”.

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()
How to&Answers:

Not the best idea but turning off this prompt would help.

  • Click the Microsoft Office Button , and then click Excel Options.

  • Click Trust Center, click Trust Center Settings, and then click Macro Settings.

  • Click the option that you want.

Answer:

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