This question already has an answer here:
- How do I call an Excel macro from Python using xlwings? 3 answers
I am having a problem getting xlwings to run a macro from Python. Despite following the code from xlwings documentation, I cannot get xlwings to execute an Excel macro. For instance, in Excel workbook named "Book.xlsm":
' in Excel workbook Book.xlsm
Sub Test()
Set ws = Worksheets("ABC")
ws.Range("A1").Value = 10
End Sub
This macro runs OK within Excel. But when I try calling this module from Python, it fails:
# in Python
import xlwings
wb = xlwings.Book('C:\\Book.xlsm')
wb.macro('Test')
print('done.')
No error messages. The Python code just runs and ends, printing the message "done." but when I check the worksheet ABC, nothing is written. Please note I am able to connect to this workbook and change cell values using xlwings. I just cannot get it to run the Test macro.
Also note I have used a much older xlwings (prior to 0.7.0, I think) before and it runs my macros with no problems. I am using the 0.10.0 version now.