Powershell - Suppress Excel Dialog Box - Merge Changes with Server

Vijeth Krishna (vijekris) 1 Reputation point
2021-05-15T18:10:47.273+00:00

Hello All,

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 PS 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

$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
Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Vijeth Krishna (vijekris) 1 Reputation point
    2021-05-25T21:50:32.603+00:00

    I might have stumbled upon a solution. Instead of using Save or SaveAS and trying to pass parameters, I used the Workbook.Close Method and passed True as a parameter which solved my problem

    Please note that if others are making changes on Excel online, this might result in merge issues. There's a checkin() and checkout() method that I'm trying to implement which should take care of this problem: More details here opening-an-excel-document-from-sharepoint-using-powershell

    $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($true)
    $x1.Quit()
    Remove-Variable wb,x1

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.