本文介绍了如何从命令行启动Excel宏(没有Worksheet_Open事件)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以从命令行启动Excel宏吗?
Is it possible to launch an Excel Macro from command line?
我不想使用 Worksheet_Open
事件,只需打开Excel文件。
I don't want to use the Worksheet_Open
event and just open the Excel File.
我需要启动Excel WorkBook中存在的特定宏。
I need to launch specific macro that exists in the Excel WorkBook.
推荐答案
最后我用了一个VB脚本,并从命令行启动它。这是我的解决方案:
Finally i used a VB Script and launched it from Command Line. This was my solution :
Option Explicit
LaunchMacro
Sub LaunchMacro()
Dim xl
Dim xlBook
Dim sCurPath
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
Set xl = CreateObject("Excel.application")
Set xlBook = xl.Workbooks.Open(sCurPath & "\MyWorkBook.xlsm", 0, True)
xl.Application.Visible = True
xl.Application.run "MyWorkBook.xlsm!MyModule.MyMacro"
xl.DisplayAlerts = False
xlBook.saved = True
xl.activewindow.close
xl.Quit
Set xlBook = Nothing
Set xl = Nothing
End Sub
这篇关于如何从命令行启动Excel宏(没有Worksheet_Open事件)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!