0

I am using python win32com library to read an excel file. Following is the snippet I use.

import win32com.client

excel = win32com.client.Dispatch('Excel.Application')
workbook = excel.Workbooks.Open("path.xlsm")
s=workbook.Sheets('Request')
print(str(s.Cells(10,18)).replace(" ","").lower())
workbook.Close()

On calling close, a VBA warning pops up. And the program execution stops till I press'OK'. Please help me in ignoring this warning? I have tried excel.DisplayAlerts = False , which didn't help

2 Answers 2

3

have you tried workbook.Close(False) ?

excel.EnableEvents = False will disable Excel Macros.

Sign up to request clarification or add additional context in comments.

7 Comments

What exactly does the warning say?
It is a custom warning user has put using VBA script. I cannot see the exact logic there. Basically, it is a reminder to save. The same can be seen when I close the excel manually. This warning won't come if I open with macros disabled using excel.
Then why can you not simply remove that line of code?
Why is that? That is the only way to get rid of the warning.
Oh, is that so? Can I open excel with macros disabled? Thanks a lot for the help
|
0

You can cheat and set:

workbook.Saved = True

before closing workbook. Excel will treat it as it is already saved.

1 Comment

So you have to probably set your path as Trusted Location. Excel -> File -> Options -> Trust Center -> Trust Center Settings -> Trusted Locations and add directory where your file path.xlsm is stored.

Your Answer

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.