Running Macros without opening excel

前端 未结 5 1256
礼貌的吻别
礼貌的吻别 2020-12-17 07:05

I wonder how would you assign VBA codes written on Excel VBA to a sort of procedure/programme or maybe dos related filepath, which you can directly without opening excel. In

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 07:49

    You can do it easily.

    Add the following content in a VBS file (e.g. example.vbs). This is only a text file that you can write using Notepad:

    'Code should be placed in a .vbs file
    Set objExcel = CreateObject("Excel.Application")
    objExcel.Application.Run "'C:\path\to\my\excel\file\myExcelMacroFile.xlsm'!MyModule.MyFunctionName"
    objExcel.DisplayAlerts = False
    objExcel.Application.Quit
    Set objExcel = Nothing
    

    Then you can double clic on the VBS file to execute it.

    Source: http://wellsr.com/vba/2015/excel/run-macro-without-opening-excel-using-vbscript/

提交回复
热议问题