Need skeleton code to call Excel VBA from PythonWin

后端 未结 2 880
故里飘歌
故里飘歌 2020-12-16 08:39

I need to invoke a VBA macro within an Excel workbook from a python script. Someone else has provided the Excel workbook with the macro. The macro grabs updated values fro

2条回答
  •  佛祖请我去吃肉
    2020-12-16 09:39

    I am sorry, I dont know python enough. However, the following should help.

    Excel's Application object has a Run method - which takes the name of the macro alongwith arguments to it.

    Lets assume that the workbook has a macro named test.

    
    Sub test(ByVal i As Integer)
    MsgBox "hello world " & i
    End Sub
    
    

    You can call this using Application.Run "test", 1234

    This will call the macro and show the messagebox with "hello world 1234".

提交回复
热议问题