--
Sub a()
\'创建外部对象,启用Python引擎
Set d = CreateObject("Stock.Python")
\'载入Python模块,模块名为MyPython
ret = d.ImportModule("jzt_MyPython1")
If ret <> 1 Then
\'载入失败,打印错误原因
Msg = d.GetErrorInfo()
Application.MsgOut Msg
Set Msg = Nothing\'使用完毕需要 Set Nothing销毁以免出现内存泄漏
Exit Sub
End If
Data = d.CallObject("pytestmodule",123,"你好")
If IsEmpty(Data) Then
Msg = d.GetErrorInfo()
Application.MsgOut Msg
Set Msg = Nothing\'使用完毕需要 Set Nothing销毁以免出现内存泄漏
Exit Sub
End If
\'打印返回值
application.MsgOut "Result:"&Data
Set d = nothing\'使用完毕需要 Set Nothing销毁以免出现内存泄
End Sub
Python模块代码:
from PythonApi import *
print(\'sss\')
您看,这样这也会显示 无效模块名jzt_MyPython1