我无法执行触发Excel宏的代码。以下是回溯的摘要。
File "c:\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 127, in Dispatch
IDispatch, userName = _GetGoodDispatchAndUserName(IDispatch,userName,clsctx)
File "c:\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "c:\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147417846, 'The message filter indicated that the application is busy.', None, None)
我尝试了各种选项来触发stackoverflow和其他一些博客中提供的excel宏,但对我没有任何帮助。
fileName = "Report_" + now.strftime("%Y%m%d") + ".xlsm"
filePath = "H:/" + fileName
xlapp = win32com.client.dynamic.Dispatch('Excel.Application')
wb = xlapp.Workbooks.Open(os.path.abspath(filePath))
xlapp.Application.Run(fileName + "!Module1.printdate")
wb.Save()
xlapp.Application.Quit()
del xlapp