【问题标题】:Block excel from opening during powershell script macro execution在PowerShell脚本宏执行期间阻止excel打开
【发布时间】:2012-08-07 21:31:23
【问题描述】:

我运行一个在后台打开 excel 文件并在其上执行宏的 powershell 脚本。问题是运行需要很长时间,有时我会忘记它正在运行并打开另一个excel实例,这会弄乱脚本。

脚本中有没有办法阻止用户打开另一个 excel 文件,或者让脚本在后台执行并允许我在前台的另一个工作簿中工作?

以下是powershell脚本的相关部分:

# Open excel
$excel = new-object -comobject excel.application
$macro = $excel.workbooks.open("C:\Users\User\AppData\Roaming\Microsoft\Excel\XLSTART\PERSONAL.XLSB")

# Get list of files to parse
$files = Get-ChildItem -Path $PWD\*.csv

# ----execute macros----

# Close excel
$macro.close()
$excel.quit()

【问题讨论】:

    标签: excel powershell vbscript vba


    【解决方案1】:

    基本上,答案是否定的。创建新对象会打开 Excel。它不可见($Excel.Visible=$true 会使其可见),但它仍然必须打开才能向其发送命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      • 2014-11-03
      • 1970-01-01
      • 2015-11-01
      • 1970-01-01
      • 2019-02-25
      相关资源
      最近更新 更多