简体   繁体   中英

How to run parallel excel macros with PowerShell?

I would like to run multiple excel macros in parallel by opening multiple instances of excel using a shell (PowerShell) script.

Examples on parallel processing in shell aren't intuitive to me (new to shell scripting).

# start excel
$excel = New-Object -comobject Excel.Application

# get files
$files = Get-ChildItem "C:\User\test"

# loop through all files in the directory
ForEach ($file in $files){

    # open the file
    $workbook = $excel.Workbooks.Open($file.FullName)

    # make file visible
    $excel.Visible = $true

    # run macro
    $app = $excel.Application
    $app.run("Macro1")
}

The code provided performs the task I want, but it does so sequentially rather than in parallel.

$app.run("application.ontime vba.now() + vba.timeserial(0,0,5),""Macro1"" ")

这将异步运行您的宏,但仍然不知道您是否要

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM