Using Python to program MS Office macros?

前端 未结 6 727
走了就别回头了
走了就别回头了 2020-12-04 11:28

I\'ve recently taken it as a project to teach myself how to program in Python. Overall, I must say that I\'m impressed with it.

In the past I\'ve typically stuck to

6条回答
  •  臣服心动
    2020-12-04 12:13

    Yes, absolutely. You want to use win32com module, which is part of pywin32 (get it here).

    I've found you can really simplify Python integration by writing a macro in VBA for Python to use, and then just have Python call the macro. It will look something like this:

    from win32com.client import Dispatch as comDispatch
    
    xl = comDispatch('Excel.Application')
    xl.Workbooks.Open("Macros.xls", False, True)
    xl.Run("Macros.xls!Macro_1")
    

    I'm sure there are plently of examples on SO... Like this one.

提交回复
热议问题