Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

excel

xlwings

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()
like image 676
Pat Chong Avatar asked Sep 28 '18 15:09

Pat Chong


People also ask

How do I integrate Excel with Xlwings?

To start using Xlwings, there are certain basic steps which are to be done almost every time. This includes opening an Excel file, viewing the sheet available and then selecting a sheet. Sheet 1 of data. xlsx file.

How do I open a macro enabled workbook?

Click on File -> Options - > Trust Center -> Trust Center Settings… -> Macro Settings -> Enable all macros.


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

like image 108
Dobert Avatar answered Sep 28 '22 20:09

Dobert