Running Macros without opening excel

前端 未结 5 1246
礼貌的吻别
礼貌的吻别 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:31

    Though the learning curve may be a bit steep, but you could consider using AutoHotKey. This allows you to create your own scripts and if so desired turn them into (rather large) .exe files. AutoHotKey is free!

    0 讨论(0)
  • 2020-12-17 07:37

    write a cmd or ps1 that opens an excel and in that excel's startup run your macro... and then when finished close it.

    this can be a solution but you are probably doing something which is unnecessary in correct planned environments.

    0 讨论(0)
  • 2020-12-17 07:42

    If the VBA in the Excel macro doesn't reference Excel objects, you can just copy the code into a text file and change the extension to .VBS. However, VB script doesn't like it when you use types, just delete the "AS something" from your Dim statement.

    I do this often to get the benefit of Intellisense, which I wouldn't have using Notepad.

    If my assumption is correct, then you probably want to change your tags to VB Scripting instead of Excel to get appropriate help.

    0 讨论(0)
  • 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/

    0 讨论(0)
  • 2020-12-17 07:52

    If I understand that right, you can simply write VBS code in a text file and rename it to .vbs (make sure file endings are visible in Windows). On doubleclick the file is executed by the Windows Scripting Host. VBS lacks some functionality of VBA but you can do a lot with CreateObject/GetObject.

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