PDA

View Full Version : calling python from VBA, excel



heatdav
07-04-2009, 12:23 AM
Hi. I apologise if this isn't the best place for this post, but wasn't sure where it should go, given it is a 2-language crossover. I'm trying to work out how I can call a python script from VBA, and have it return the outputs from python back to VBA. My ultimate goal is to have a VBA function that takes as it's input, a range of cells in excel with some python code in, call python,run them, and output in the cell with the function call, an array formula containing the outputs from python. For example, I would put in

cell A1:
a = ['spam', 'eggs', 100, 1234] cell A2:
a
and my VBA function would go in cell A3:
cell A3:
=myVBACallToPython(A1:A2)
which would return in cells A3 : D3 (when expanded as an array formula)
cell A3 = spam
cell B3 = eggs
cell C3 = 100
cell D3 = 1234

Does anyone know how I could go about doing this?