I am creating a Python script to paste values pulled from another file into an Excel template.
The Excel template contains many macros that process the data it is given. This data is then sent to the clipboard, and the unsaved Excel file is then closed.
I have used a combo of xlwt and xlrd (it's a .xls file) to try and write to the Excel file, but it seems that these commands access the file without explicitly opening it (the Excel file never comes on screen).
I was curious if anyone could point me in the right direction of some tools that would allow me to explicitly open an Excel file (e.g. subprocess.call()), paste the data into some cells, then let the user do the rest.
Any help or criticism is appreciated.
EDIT: I have been trying to use pywin32 for my purposes. It's not quite working. While it can successfully open the Excel file and run the macro, it cannot pass any values into the textbox of the macro.
Here is my current code:
import win32com.client as win32
import time
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(r'C:\Users\me\Desktop\file.xlsm')
excel.Visible = True
#if I run wb.Application.SendKeys(1) here, it places a 1 into a cell on the worksheet
wb.Application.Run('Set_Up_Sheet') #running the macro, which successfully launches
time.sleep(2)
wb.Application.SendKeys(1) #this seems to have no effect
How can I send values to this macro's textbox?