1

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:


Error

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.

1 Answer 1

1

I managed to fix the problem. I was importing clr before xlwings, so by importing xlwings first solved the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.