I know that I can run a VBA script in excel with a keyboard shortcut so I could package my python code as a user defined function and then call it through VBA but that is inelegant.

Is there a better way to do this?

有帮助吗?

解决方案

The best way is to use VBA to call a Python script, rather than a user-defined function. You can do that with this code:

Sub call_DN()
    Application.COMAddIns("DataNitro.DataNitro").Object.RunScript ("test.py")
End Sub

That gives you more flexibility than packaging the code as a UDF. It's still not ideal to go through VBA, but there's no other option right now.

[Source: I'm one of the DataNitro developers]

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top