How do I call an Excel macro from Python using xlwings?

前端 未结 5 797
孤独总比滥情好
孤独总比滥情好 2020-11-27 20:11

I\'ve read the API docs for xlwings, and played around with Workbook and Sheet objects in the interpreter, but I can\'t figure out how to call a macro from Python.

H

5条回答
  •  悲&欢浪女
    2020-11-27 20:22

    I got issues when I updated xlwings to 0.9+ version. To run vba macro with xlwings, I used the code written below for running macros inside the personal workbook (PERSONAL.XLSB). The updated code no2 of Felix didn't work for me, for macro inside the personal workbook.

    import xlwings
    
    wb = xw.Book(excel_file_path)
    app = wb.app
    # into brackets, the path of the macro
    macro_vba = app.macro("'PERSONAL.XLSB'!my_macro") 
    macro_vba()
    

    Hope it will help.

提交回复
热议问题