0
votes

I run a powershell script that opens excel files in the background and executes macros on them. The trouble is that it takes a long time to run, and sometimes I forget it's running and open another instance of excel, which messes up the script.

Is there a way in the script to block the user from opening another excel file or alternatively, make the script execute in the background and allow me to work in another workbook in the foreground?

Here are the relevant parts of the powershell script:

# 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()
1

1 Answers

0
votes

Basically, the answer is no. Creating the new object opens Excel. It's not visible ($Excel.Visible=$true would make it visible), but it still has to get opened in order that you can send commands to it.