【问题标题】:Click VBA button in excel using powershell使用powershell在excel中单击VBA按钮
【发布时间】:2018-02-08 00:59:19
【问题描述】:

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

谢谢!

【问题讨论】:

标签: excel vba


【解决方案1】:

你只需要运行这个 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

【讨论】:

    【解决方案2】:

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

    适合您的步骤:

    1. 从 VBA 项目中获取宏名称(主子)。
    2. 获取系统上 excel 应用程序的路径。
    3. 获取存储VBA宏的excel文件路径。

    尝试使用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-18
      相关资源
      最近更新 更多