I have Powershell script that calls an Excel VBA script and saves the file. I'm running into an issue while closing the workbook as I get a dialog box "Would you like to merge your changes with the latest updates on the Server?"
and PowerShell waits for user confirmation. How do I suppress this notification? I have enabled displayAlerts = $false but that doesn't seems to be working in this case
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
SaveAs()
to the same path? As an aside, I prefer using this module to the ComObject - ImportExcel – AshSaveAs($filename, 52, [Type]::Missing, [Type]::Missing, $false, $false, 1, 2)
- Workbook.SaveAs. Parameters explained named in orderFileName, FileFormat (52 for xlsm), Password (Can't be null, so use Type.Missing), WriteResPassword (Type missing again), ReadOnlyRecommended, CreateBackup, Access Mode (1 - do not change access mode), ConflictResolution (2 - User changes always accepted)
. You can see links to some of the values on the linked page. – AshSaveAs($filename)
the document gets saved to the My Documents Folder instead of the folder path that it is originally in. I tried passing the full path of the file and I get this errorUnable to get the SaveAs property of the Workbook class At line:1 char:1 + $wb.SaveAs("C:\Users\*\OneDrive \*\vb test ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
– shreyasfifa