简体   繁体   中英

How can I bypass this Powershell warning message?

I have always used this script to open an Excel workbook automatically, save it and use it. Since the workbook has been modified the script does not work, because every time I open the file a popup appears that warns me that there are errors inside the workbook.

How can I bypass this problem and make Powershell press the "ok" button in the warning message to continue with the update?

在此处输入图片说明

$file = 'C:\Users\User\Desktop\SPC_Analysis_v2.3 - 36 mesi_250_macchine_IPC - Copia - Copia.xlsm' 
$x1 = New-Object -ComObject "Excel.Application"
$x1.Visible = $false                
$enddate = (Get-Date).tostring("dd-MM-yy HH-mm-ss")  
$filename = 'C:\Users\User\Desktop\SPC\IPC\IPC_QCP - Copia ' + $enddate + '.xlsm' 
$wb = $x1.workbooks.Open($file) 
$wb.RefreshAll() 
$wb.SaveAs($filename) 
$wb.Close() 
$x1.Quit() 
Remove-Variable wb,x1

You can turn off alerts using:

$x1.DisplayAlerts=$False

This will turn off all alerts on Excel (except critical errors). Because it turns off all alerts, make sure you turn them on after you are done!

$x1.DisplayAlerts=$True

Source: https://social.technet.microsoft.com/Forums/windows/en-US/d963956a-02c4-488f-b59c-bb730b1506b0/displayalerts-false-is-not-working?forum=winserverpowershell

Info about property DisplayAlerts:

DisplayAlerts

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