I'm writing a Python script to automate a process that uses Excel macros to format files to input into a different program later on. I'm a bit new to Python and completely new to VBA, but I think I have the steps down.
So far I have this to run the macro itself (with help from other SO posts):
xl = win32com.client.DispatchEx('Excel.Application')
xlpath = os.path.expanduser(xlfile)
wb = xl.Workbooks.Open(Filename=xlpath, ReadOnly=1)
xl.Run("my_macro")
At this point the macro runs and calls Application.GetOpenFilename() to open a dialog for the user to choose the file to be formatted, which is going to be different for each macro.
Basically my user is going to have different initial data to format each time they run my script. At the beginning I want them to choose the files that they need formatted and then I'll save those file paths. Then I want to plug those file paths into the macro from Python instead of opening the dialog in Excel.
Is there a way to do this directly by changing the macro? If not, will I need to rewrite the macro in Python with one of the modules out there for driving Excel?