I'm encountering a similar problem to these two questions:
I recently uninstalled Office / Excel 2010 and I'm getting the error since then. I now only have Office 365, version 16.0.12872.20200 32bit. I've tried uninstalling and re-installing xlwings and the entire conda virtual env I'm working in. xlwings used to sometimes open Excel 2010 in spite of the newer install.
If I try to run app = xw.App()
, book = xw.Book()
, book = xw.Book(r"path\to\file.xlsx")
, etc I get the following error:
Traceback (most recent call last):
File "<ipython-input-12-437cd03edaeb>", line 1, in <module>
app = xw.App()
File "C:\Users\User\Anaconda3\envs\emp_hist_env\lib\site-packages\xlwings\main.py", line 210, in __init__
self.impl = xlplatform.App(spec=spec, add_book=add_book)
File "C:\Users\User\Anaconda3\envs\emp_hist_env\lib\site-packages\xlwings\_xlwindows.py", line 299, in __init__
self._xl = COMRetryObjectWrapper(DispatchEx('Excel.Application'))
File "C:\Users\User\Anaconda3\envs\emp_hist_env\lib\site-packages\win32com\client\__init__.py", line 113, in DispatchEx
dispatch = pythoncom.CoCreateInstanceEx(clsid, None, clsctx, serverInfo, (pythoncom.IID_IDispatch,))[0]
com_error: (-2147221005, 'Invalid class string', None, None)
If, however, Excel is running, then app = xw.App()
still doesn't work, but book = xw.Book()
, book = xw.Book(r"path\to\file.xlsx")
do. It looks like xlwings can't find the excel app instance.
I'm trying to avoid reinstalling Office 365 or worse, Office 2010. Any ideas of easy settings I can change with xlwings or a quick registry tweak that may be fix it?
I ended up fixing the problem by uninstalling both MS Office and Anaconda. I reinstalled Office 365 but ended up installing Miniconda instead of Anaconda to manage my environments a little more closely.
I noticed that in the install folder (C:\users\user
) there was a \.xlwings
folder I wish I'd noticed right away. Deleting it after removing xlwings might have saved me some time. I only noticed it when I was clearing Anaconda files left by the uninstaller.