Python - run Excel macro

前端 未结 2 1573
说谎
说谎 2020-12-11 07:26

I would like to use Python to run a macro contained in MacroBook.xlsm on a worksheet in Data.csv.

Normally in excel, I have both files open and shift focus to the Da

相关标签:
2条回答
  • 2020-12-11 08:04

    1) you can't have VBA on a *.csv file. You need the *.xlsm file to be the active workbook. I don't think you need to open the *.csv file at all if your macro know how to find it.

    2) Enable VBA module access in your Office Excel:

    File
    options
    Trust Center
    Trust Center Settings
    Macro Settings
    Enable VBA access
    

    3)I am using this function to run macros:

    excel.Application.Run("FilterLoans")
    
    0 讨论(0)
  • 2020-12-11 08:19

    Try savin the macro to your "Normal" Project and call.

    excel.Application.Run("Normal.ModuleName.SubName")
    

    You can even add the Module to the Normal profile programmatically, but Office doesn't let you do it if you have insufficient access rights.

    0 讨论(0)
提交回复
热议问题