I have a python script which i converted into a COM server. Now i want to call it from VBA (Access).
I have tried this:
Sub test()
Dim PyScript
Dim var
Set PyScript = CreateObject("PythonDemos.CodeScript")
var = PyScript.CodeReader()
Debug.Print var
End Sub
But i get an error at CreateObject(...): Automation error 2147024770
From what i read this means that the module "PythonDemos" can not be found.
Here is the python code:
class Main:
_public_methods_ = ['CodeReader']
_reg_progid_ = "PythonDemos.CodeScript"
_reg_clsid_ = "{B74B241B-0699-4332-8145-145512D332D1}"
def CodeReader(self, item=None):
#do stuff here and return values
if __name__ == '__main__':
win32com.server.register.UseCommandLine(Main)
It runs well on its own and was registered without problems as COM server.
My Question is: How to call this python script correctly from vba? Where is my mistake?