Using Python to program MS Office macros?

前端 未结 6 720
走了就别回头了
走了就别回头了 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

    This is a question from a long time ago, but I'm putting it here so others can point to it in their search.

    One option not discussed here, which I use all the time, is to create a COM server from Python and call it from VBA in any Office application. There is a good tutorial of doing COM server with Python at: http://timgolden.me.uk/pywin32-docs/html/com/win32com/HTML/QuickStartServerCom.html

    What you end up with is a COM server (don't forget to make it In Process) that can be created by a call to CreateObject() in VBA. You then call the methods on it as you do with an COM object created with CreateObject(). You can't single step in your Python script, but you can intercept logging with win32traceutil from Pywin32 distribution. Works flawlessly.

提交回复
热议问题