I am trying to find the currently open excel file using win32com. Below is my code:
import win32com.client
excel = win32com.client.GetActiveObject('Excel.Application')
wb = excel.Workbooks(2)
I tried different numbers instead of 2 ( excel.Workbooks(2)). Does anybody have any idea why it not working? Thanks in advance
1 Answer 1
Not sure about win32com.client but xlwings can be used to detect active excel.
import xlwings as xw
print(xw.books.active.name)
Sign up to request clarification or add additional context in comments.
Comments
lang-py