报错如下: msWord = win32com.client.Dispatch( "Word.Application" )
File "C:\Python26\lib\site-packages\win32com\client\__init__.py", line 95, in
Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c
lsctx)
File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 108, in
_GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python26\lib\site-packages\win32com\client\dynamic.py", line 85, in _
GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II
D_IDispatch)
com_error: (-2146959355, '\xb7\xfe\xce\xf1\xc6\xf7\xd4\xcb\xd0\xd0\xca\xa7\xb0\x
dc', None, None)
解决办法:先把python程序和word进程都关掉。手动启动word,提示说上次启动不正常,进入安全模式启动。启动后,我发现左侧有很多恢复的word文档,这些文件没有什么实际意义了,就点击了关闭。第二次手工启动word就正常了。
感觉应该是手工正常启动一下word就能解决问题了,否则程序一直会报错。