0
votes

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

1 Answers

0
votes

Not sure about win32com.client but xlwings can be used to detect active excel.

import xlwings as xw
print(xw.books.active.name)