1

I just discovered win32com, I got to know I can code excel macros in python using this, but I could not find any document which teach me how to code macros using win32com. I am looking for some doc which provide all win32com tools with examples.

2 Answers2

1

There is no such document. The macros that Excel creates natively are in VBA using COM API, which is same API as used in Python. So the closest you can get is to record a macro using Excel, then look at the VBA code and convert it to the equivalent Python code that uses win32com. You can also search the MSDN docs for the Excel Interop; the functions, classes etc are all identical in win32com. The only tricky aspect of using win32com is the constants; to use those, you have to first generate the Python type library for Excel, using EnsureDispatch or gencache (see Accessing enumaration constants in Excel COM using Python and win32com and error xlPrimary not defined in Python win32com for more info).

Community
  • 1
  • 1
Oliver
  • 27,510
  • 9
  • 72
  • 103
  • If one of the answers answered your question please accept it, or add comment for what is missing, or consider deleting your question. – Oliver Dec 30 '14 at 22:29
1

http://pythonexcels.com/mapping-excel-vb-macros-to-python/. Here you can easily learn it.