2

I have a script that opens an Excel spreadsheet and then goes to a specific sheet before running a macro. The problem is that this macro brings up different dialog boxes which require user input - I am trying to automate the process. I have tried to get rid of these boxes by using the following code:

import os
impor win32com.client

xl = win32com.client.Dispatch('Excel.Application')
xl = DisplayAlerts = False #Supposed to disable alert/messages/dialog boxes
wb = xl.Workbooks.Open(os.path.abspath('Test.xlsm'), ReadOnly = 0) #Opens spreadsheet
wb.Worksheets('Assets').Activate() #Activates correct sheet
wb.Application.Run('MxRunAction') #Runs macro
wb.Clost(True)

I have read on many threads that:

Application.DisplayAlerts = False

is supposed to fix this problem, yet this seems to do nothing if I substitue Application with xl for my case. Am I using it properly in this sense?

5
  • I don't know a thing about Python, but in VBA it would be Application.DisplayAlerts = False ... So, wouldn't that translate to xl.DisplayAlerts = False instead of xl = ...? Commented Dec 4, 2018 at 6:54
  • That's what I have tried using but it doesn't seem to do anything to the message boxes. Commented Dec 4, 2018 at 6:58
  • If the code explicitly pops up a messagebox (or some other dialog) then DisplayAlerts (or any other setting) isn't going to change that behavior... Commented Dec 4, 2018 at 6:58
  • The macro that runs is password protected and unfortunately I can't change it. Is there something I can write that could auto-select the options? Commented Dec 4, 2018 at 7:06
  • Likely you would need some Windows API calls in order to locate and click the desired button(s). That will not be super-simple... Commented Dec 4, 2018 at 18:16

1 Answer 1

1

That would be the Application need to be closed

xl.DisplayAlerts = False
Sign up to request clarification or add additional context in comments.

Comments

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.