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
Info about property 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.