Reputation: 17
I have been having issues finding an answer for this one. I am currently utilizing win32com, but while it is very powerful, I cannot figure out how to tap into an Excel file that's already open.
There is no alternative ; an external script opens Excel and writes to it the data, it is not located on the hard disk
Upvotes: 2
Views: 4556
Reputation: 159
I haven't got enough reputation to upvote Maxime Biette's answer but it's the right one.
If you just want one specific sheet to be saved:
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
print("Active WB:", excel.ActiveWorkbook.Name)
for wb in excel.Workbooks:
if wb.Name == 'thenameofyourfile.xlsx' :
print("WB:",wb.Name)
wb.Save()
Upvotes: 2
Reputation: 303
You can access all the opened workbooks by looping through Excel.Application.Workbooks:
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
print("Active WB:", excel.ActiveWorkbook.Name)
for wb in excel.Workbooks:
print("WB:",wb.Name)
wb.Save()
Upvotes: 4