【问题标题】:Powershell to wait a macro to be executed in ExcelPowershell 等待宏在 Excel 中执行
【发布时间】:2019-05-18 22:32:52
【问题描述】:

我正在使用一个非常简单的 powershell 打开一个 excel 文件,运行一个宏并保存文件。

这个宏基本上就是DATA标签下的REFRESH ALL按钮。

我的问题是 Excel 挂在 Save 阶段,因为 REFRESH ALL 永远不会完成。

如果我在命令之间添加暂停。我可以毫无问题地正常进步。

clear

$file = "\\website\folder\file.xlsm"

$displayname = $File.split("\")[$File.split("\").count-1]

Write-Host "Creating Excel Instance for $displayname"

$Excel = New-Object -ComObject Excel.Application

Write-Host "Opening $displayname"

$Excel.Visible = $True

$Excel.StatusBar = "Opening the file... Please be patient..." 

$Workbook = $Excel.Workbooks.Open($file)

Write-Host "Running Refresh Query"

$Excel.StatusBar = $False

$Excel.Run("Refresh_All")

PAUSE ## This pause is needed in order to wait the Macro to happen

Write-Host "Saving $displayname" 

$Workbook.Save()

Write-Host "Close Excel Instance"

$Excel.Quit()

如果尝试读取 $excel.Ready 状态...但始终准备就绪...

我正在寻找一种方法来读取状态栏并识别正在运行的背景查询消息并在完成后保存文件。

有什么提示吗?

【问题讨论】:

    标签: excel vba powershell


    【解决方案1】:

    我找到了解决办法...

    解决方案:“转到数据选项卡,单击连接组中的连接,单击每个连接并单击属性,取消选中“启用后台刷新”框。” (tylerlohman@gmail.com,pcreview,2013)。

    【讨论】:

      猜你喜欢
      • 2016-03-04
      • 2012-10-13
      • 2021-10-27
      • 2021-10-10
      • 2022-12-18
      • 2012-08-07
      • 1970-01-01
      • 2012-05-03
      • 1970-01-01
      相关资源
      最近更新 更多