Access Microsoft Automation Objects with Python

I have a set of macros that I turned into an add-in in excel. Macros allow me to interact with another program called Microsoft Automation Objects, which provides some control over what another program is doing. For example, I have a filter tool in an add-in that filters the list provided by another program to match the list in the Excel workbook. However, it is slow. I can have fifty thousand rows in another program and you want to filter out all the rows that do not match the list of three thousand rows in Excel. This type of compliance takes about 30-40 minutes. I began to wonder if there is a way to do this with Python, because I suspect that the matching process can be completed in a few seconds.

Edited by:

Thanks. On the offer to take a look at Hammond's book, I learned a number of resources. However, although I am still studying this, it looks like many of them are old. For example, Hammond’s book was published in 2000, which means that the letter was completed almost ten years ago. Adjustment I just found a package called PyWin32 with build 2/2009.

That should make me start. Thanks

+4
source share
4 answers
Mark Hammond and Andy Robinson have written a book on accessing Windows COM objects from Python.

Here is an example using Excel.

+5
source

You will probably need the win32com package.

This is an example that I found in: http://www.markcarter.me.uk/computing/python/excel.html that shows how to use com with Excel. This could be a good start.

# this example starts Excel, creates a new workbook, # puts some text in the first and second cell # closes the workbook without saving the changes # and closes Excel. This happens really fast, so # you may want to comment out some lines and add them # back in one at a time ... or do the commands interactively from win32com.client import Dispatch xlApp = Dispatch("Excel.Application") xlApp.Visible = 1 xlApp.Workbooks.Add() xlApp.ActiveSheet.Cells(1,1).Value = 'Python Rules!' xlApp.ActiveWorkbook.ActiveSheet.Cells(1,2).Value = 'Python Rules 2!' xlApp.ActiveWorkbook.Close(SaveChanges=0) # see note 1 xlApp.Quit() xlApp.Visible = 0 # see note 2 del xlApp # raw_input("press Enter ...") 
+14
source

As far as I know, in Python on Windows, you can create COM objects (which are automation objects). Then, assuming you can exit the lists using automation, it should be easy to do what you want in python.

0
source

However, although I am still studying this, it looks like many of them are old.

COM is deprecated. The interface has not changed since at least 1993.

I also do not see the package on the Python.org website. I searched for COM packages but did not see anything useful.

http://python.net/crew/mhammond/win32/ http://sourceforge.net/projects/pywin32/

The last update was February 2009, including support for Python 3.0.

0
source

All Articles