我试图从excel中的按钮运行RunPython函数。我希望函数从excel中的一个框中获取参数,如下所示:
Sub ImportData()
Dim choice As String
choice = Range("B2").Value
RunPython ("import Excel_module; Excel_module.importing_data(choice)")
End Sub
这有可能吗?如果是这样,我该如何编写代码?我宁愿不使用UDF。
你可以用两种方式做到这一点:
1)通过使用RunPython
:
您需要使用字符串连接:
RunPython ("import Excel_module; Excel_module.importing_data(" & choice & ")")
2)或者,如果您只在Windows上,那么您也可以使用xw.sub
装饰器并使用VBA中的导入函数,就像它是本机VBA函数一样,请参阅docs。它目前没有在文档中显示,但它们接受参数。