I have a python script that uses win32com to run a VBA Macro on a Excel file. The problem is that if there is an exception in the VBA Macro, Excel will open with a dialog box asking the user to continue.
This will block the rest of the python execution until the user answer the dialogbox.
As my application will be run on a server to generate multiple Excel file, there won't be a user to close the dialog box.
How could I ignore the Excel dialog box when there is an error so my application can keep running ?
Here is my python code :
import comtypes
comtypes.CoInitialize()
import win32com.client
excel = win32com.client.DispatchEx("Excel.Application")
excel.DisplayAlerts = False
wb = excel.Workbooks.Open(Filename=excel_file)
try:
excel.Run('ReportModule.Compute')
wb.Save()
except Exception as e:
logging.error('Failed to run macro for {}.'.format(excel_file))
logging.error(e, exc_info=True)
excel.Quit()