Suppress Excel Save Dialog Box in PowerShell

shreyasfifa

New Member
Joined
Aug 9, 2016
Messages
2
Hello All,


I have Powershell script that calls an Excel VBA script and saves the file. I'm running into an issue while saving the workbook as I get a dialog box "Would you like to merge your changes with the latest updates on the Server?" and PS waits for user confirmation. How do I suppress this notification? I have enabled displayAlerts = $false but that doesn't seems to be working

The file sits on a shared onedrive folder location which is prompting Excel to ask this question

$file="test - Copy v4.xlsm"
$x1 = New-Object -ComObject "Excel.Application"

$x1.displayAlerts = $false # don't prompt the user
$x1.Visible = $false

$wb = $x1.workbooks.Open($file)

$x1.Run('MACRO_NAME')

$wb.Save()
$wb.Close()
$x1.Quit()
Remove-Variable wb,x1
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I really don't know much Powershell at all, but you could try the equivalent of Application.EnableEvents = False, which I suspect would translate to: $x1.EnableEvents = $false, and maybe put it just before wherever you get the message. The problem with disabling events is that it could result in the macro not working where, as you might expect, it relies on events in order to operate correctly. The only other thing is - are you certain that it is Excel raising this dialog box? I have a sneaking suspicision that it's OneDrive that's doing it, in which case you're going need to be a bit more creative in how to solve this one... :-) I gather that Powershell has SendKeys functionality and can control the mouse....
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top