Reputation: 21
I am using the xlwings library to run python in VBA Sub. Inside the python module I import the CLR library to call C# classes. When I run the code in Excel it returns the following:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "t:\development\retailPythonModule.py", line 11, in <module>
import xlwings as xw
File "C:\ProgramData\Anaconda3\lib\site-packages\xlwings\__init__.py", line 23, in <module>
from . import _xlwindows as xlplatform
File "C:\ProgramData\Anaconda3\lib\site-packages\xlwings\_xlwindows.py", line 25, in <module>
from comtypes import IUnknown
File "C:\ProgramData\Anaconda3\lib\site-packages\comtypes\__init__.py", line 165, in <module>
CoInitializeEx()
File "C:\ProgramData\Anaconda3\lib\site-packages\comtypes\__init__.py", line 156, in CoInitializeEx
_ole32.CoInitializeEx(None, flags)
File "_ctypes/callproc.c", line 918, in GetResult
OSError: [WinError -2147417850] Cannot change thread mode after it is set
Press Ctrl+C to copy this message to the clipboard.
OK
This code works fine in Jupiter notebook, it's only when I try to run it through excel.
Please help, I am still very new in this.
Upvotes: 1
Views: 687
Reputation: 21
I managed to fix the problem. I was importing clr before xlwings, so by importing xlwings first solved the problem.
Upvotes: 1