0

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

asked Jan 27, 2021 at 1:42

1 Answer 1

1

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

import xlwings as xw
print(xw.books.active.name)
answered Jan 29, 2021 at 16:18
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.