1

I would like to manipulate an Excel spreadsheet from Python, e.g. open it, and execute an embedded VBA macro, or some set of actions on the data inside. I have a choice of whether I would like to work on Windows or Linux for this.

There are packages ways to do this (xlwings package from this answer) but I am looking for something more native to explore what options are there.

I think one way to do this is the COM interface on Windows, which xlwings itself wraps. I found win32com python module, but seem to have very little documentation on manipulating particular objects, and what methods and attributes are available. Can someone please point me to a good information source (books are also ok)?

Alternatively, are there other options to do this, and if so, where can I read up on them?

1

1 Answer 1

2

I have gotten around this by using the Auto_Open() function in VBA, which runs when the Excel file opens.

Public Sub Auto_Open()
     ''' Run other macro here
End Sub

You could then open the Excel file using subprocess.popen. This is a bit of a hack, but avoids using win32com. I had to take this route because win32com wouldn't work on our locked down computers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.