Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88854

Excel crashes when i set com object to call python script

$
0
0

I am running windows10 on an azure vm with Office365 Pro Plus. I am trying to set up a COM object to call a python script a la this:

http://exceldevelopmentplatform.blogspot.com/2018/01/calling-python-class-using-vba-with-com.html

I was able to get the clsid with pip install pywin32 -> [python shell] import pythoncom -> print(pythoncom.CreateGuid()) and so my python script is very simple.

Just trying to test if it works:

class PythonClass1(object):
    _reg_clsid_= "{<Guid from script above here>}"
    _reg_progid_= 'PythonLib1.PythonClass1'
    _public_methods_ = ['Greeting']

    def Greeting(self):
        print("this work?")
        return "Hello World"

if __name__=='__main__':
    print("Registering COM server...")
    import win32com.server.register
    win32com.server.register.UseCommandLine(PythonClass1)

I am trying to call this from vba in excel like so:

Sub TestingButton_Click()
    Dim objPython As Object
    Set objPython = CreateObject("PythonLib1.PythonClass1")
    Debug.Print objPython.Greeting()
End Sub

When I run this module, i get a loading spinner on my cursor for about 5 seconds then excel just crashes and restarts excel with a version recovery bar on the left side just like when excel crashes normally.

I'm absolutely at a loss for why this would happen. I've tried debug.print-ing all over in vba and also in the python script. Nothing in the win32traceutil.py, no errors... just crashes and restarts.

Does anybody have any ideas as to what's going on? Any help would be greatly appreciated, thank you in advance.


Viewing all articles
Browse latest Browse all 88854


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>