Sub Test()
Dim d1 '创建一个变量
'创建Array外部对象,将对象实例置变量d1中
Set d1 = CreateObject("Stock.Array")
d1.AddBack(1)
d1.AddBack(2)
'创建外部对象,启用Python引擎
Set d = CreateObject("Stock.Python")
'载入Python模块,模块名为MyPython
ret = d.ImportModule("jzt_ta")
If ret <> 1 Then
'载入失败,打印错误原因
Msg = d.GetErrorInfo()
Application.MsgOut Msg
Set Msg = Nothing '使用完毕需要 Set Nothing销毁以免出现内存泄漏
Exit Sub
End If
'调用Python模块函数,函数名pytestmodule,参数为Array外部对象d1
set Data = d.CallObject("zhibiao_vba",d1,d1)
If IsEmpty(Data) Then
Msg = d.GetErrorInfo()
Application.MsgOut Msg
Set Msg = Nothing '使用完毕需要 Set Nothing销毁以免出现内存泄漏
Exit Sub
End If
'打印返回值
application.MsgOut Data.GetAt(1)
Set d = nothing '使用完毕需要 Set Nothing销毁以免出现内存泄漏
set d1 = nothing '使用完毕需要 Set Nothing销毁以免出现内存泄漏
end Sub
call Test
python模块中代码
from PythonApi import * |
这种不行的,vba和python不一样,有些格式没有办法的