如何设置COM对象以使用Excel VBA调用Python脚本?

如何设置COM对象以使用Excel VBA调用Python脚本?,python,excel,vba,com,Python,Excel,Vba,Com,我使用Office 365 Pro Plus在Azure虚拟机上运行windows 10 我正在尝试设置一个COM对象,将Python脚本称为la 我得到了clsid pip install pywin32 -> [python shell] import pythoncom -> print(pythoncom.CreateGuid()) 所以我的Python脚本非常简单 要测试它是否有效,请执行以下操作: class PythonClass1(object): _reg

我使用Office 365 Pro Plus在Azure虚拟机上运行windows 10

我正在尝试设置一个COM对象,将Python脚本称为la

我得到了clsid

pip install pywin32 -> [python shell] import pythoncom -> print(pythoncom.CreateGuid())
所以我的Python脚本非常简单

要测试它是否有效,请执行以下操作:

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)
我在光标上放置了一个加载微调器大约5秒钟,然后Excel崩溃,并用左侧的版本恢复栏重新启动,就像Excel正常崩溃时一样


我在VBA和Python脚本中尝试了debug.print-ing。win32traceutil.py中没有任何内容,没有错误。

导入模块pythoncom后,将
\u reg\u clsctx\u=pythoncom.clsctx\u LOCAL\u服务器添加到类中。那帮我修好了