在ThisWorkbook中声明了Public Sub的Excel文件:
Public Sub Build(data)
Me.Sheets(1).Range("A1") = "Hello, world! " & data
End Sub
有一个python脚本需要打开Excel文件并运行在sub:
之上import win32com.client, os
xla = win32com.client.DispatchEx('Excel.Application')
xlb = xla.Workbooks.Add(os.getcwd()+r'\test.xls')
VbMethod = 1
try:
# Error: object has no attribute 'Build'
xlb.Build('data')
# CallByName should help, but how do I call it from python?
# CallByName(xlb,'Build',VbMethod,xla,'data')
finally:
xlb.Close()
xla.Quit()
请告知我如何从python中调用Sub?提前谢谢!