7

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()
Pat Chong
  • 71
  • 4

2 Answers2

1

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.

Dobert
  • 36
  • 5
  • 1
    Thanks for the suggestion. Unfortunately, the script will run on multiple computers so, it's unrealistic to assume each user will have the same settings. – Pat Chong Sep 28 '18 at 15:46
  • All I can think about in sucvh situation is changing registry settings for Trust Center [link](https://blogs.technet.microsoft.com/diana_tudor/2014/12/02/microsoft-project-how-to-control-macro-settings-using-registry-keys/). You could try doing it in your VBA [link](https://stackoverflow.com/questions/32345238/read-and-write-from-to-registry-in-vba). So users get the message only once. But this is just a theory, I haven't tried it myself. – Dobert Oct 02 '18 at 11:16
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

jkpieterse
  • 2,727
  • 1
  • 9
  • 18