Using the active workbook in python script with openpyxl?

Viewed 483

I am trying to run a python script from a vba excel macro. I am using openpyxl

I have a button in my custom ribbon calling the sub-RunPythonScript ()

Set objShell = VBA.CreateObject("Wscript.Shell")
objShell.Run sPathPythonExe & sPathPythonScript & sPythonScriptFileName

This works because I have hardcoded the full path of the xls I want to use (for testing)

TheFilePathXLS = r'C:\Users\aa\bb\cc\targetxls.xlsx'
thetargetxlswb = openpyxl.load_workbook(TheFilePathXLS)

I would like to change this so that the python script picks up the (open) active worksheet. How do I do that? In the vba macro, I can set up a simple line to get the top active workbook full path

TheFilePathXLS = ActiveWorkbook.FullName

Do I need to pass this as an argument? if so what is the best/easiest way of doing this?

Thanks in advance.

0 Answers
Related