vba 使用 Bat 脚本运行 Excel 宏(单击按钮)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23750679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running Excel Macro (Button Click) using Bat script
提问by Nitin Jadhav
I have written an excel Macro, that runs on a button click in Excel.
我写了一个 excel 宏,它在 Excel 中单击按钮运行。
I want to run the same macro using bat script, i.e. I want to open the excel and click the Button using bat scripting.
我想使用 bat 脚本运行相同的宏,即我想打开 excel 并使用 bat 脚本单击按钮。
I have succeeded in opening the excel sheet but I am unable to run the VBA code(i.e. Click the Button)
我已成功打开 Excel 表格,但无法运行 VBA 代码(即单击按钮)
I have written the VBA code in following function
我在以下函数中编写了 VBA 代码
Private Sub CommandButton1_Click()
...
...
End Sub
I have tried the following code for bat script-
我已经为 bat 脚本尝试了以下代码-
Start G:\Excel\test.xlsm
Run(CommandButton1_Click)
Pause
Thanking In anticipation
期待中的感谢
采纳答案by Petay87
I would recommend that you just add the following Sub:
我建议您只添加以下子项:
Private Sub Workbook_Open()
Call CommandButton1_Click
End Sub
This will run your CommandButton1_Click as soon as the workbook opens.
这将在工作簿打开后立即运行您的 CommandButton1_Click。