使用powershell单击excel中的VBA按钮

时间:2017-07-05 12:45:32

标签: excel excel-vba vba

我需要在Excel中自动执行某些操作。第一步应该是运行通过单击VBA-Button启动的宏。有没有办法可以使用Powershell单击VBA-Button?

谢谢!

2 个答案:

答案 0 :(得分:0)

提供隐藏在此按钮内的宏名称,作为cmd命令的参数。

您的步骤:

  1. 从VBA项目中获取宏名称(主要子)。
  2. 在您的系统上获取Excel应用程序的路径。
  3. 获取存储VBA宏的excel文件的路径。
  4. 尝试使用Powershell运行:

    "path_to_excel_app" "path_to_excel_file_with_macro" /x macro_name
    

    以下是我使用MS访问的工作:

    "C:\Program Files (x86)\Microsoft Office\Office15\MSACCESS.EXE" "R:\path_to_macro_file\AccessFileWithMacro.accdb" /x macroName
    

答案 1 :(得分:0)

您只需要运行此PS

# start Excel
$excel = New-Object -comobject Excel.Application
#open file
$FilePath = 'FilePath'
$workbook = $excel.Workbooks.Open($FilePath)
##If you will like to check what is happend
$excel.Visible = $true
## Here you can "click" the button
$app = $excel.Application
$app.Run("MacroName")

       ##The macro name is the trigger of your button
相关问题