Ignoring warning/error popup messages for Excel script

Welcome Forums General PowerShell Q&A Ignoring warning/error popup messages for Excel script

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
2 years, 10 months ago.

  • Author
    Posts
  • #33096

    Participant
    Points: 0
    Rank: Member

    I would like to know how to ignore warning/error popups while running Powershell for Excel com objects. However I'd still like the errors to be logged in the Powershell console (as it is with my current code below).

    I'm running the following code as of now:

    $files = Get-ChildItem -Path "D:\Product Feeds\" *.xlsx -Recurse
    $xl = New-Object -ComObject Excel.Application
    foreach ($file in $files) {
    
        $newFile = "$($file.DirectoryName)\$($file.BaseName).csv"
        $wb = $xl.Workbooks.Open($file.FullName)
        $wb.RefreshAll()
        if (Test-Path -Path $newFile) {
            
            Remove-Item $newFile -Force
        
        }
        $wb.SaveAs("$newFile",6)
        $wb.Close($true)  
           
    }
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl)
    

    Thanks in advance 🙂

  • #33110

    Participant
    Points: 4
    Rank: Member

    Can you give us some idea of what the errors are and what the pop-ups say. I didn't get any errors or pop-ups when testing this.

  • #33156

    Participant
    Points: 0
    Rank: Member

    Hi Matt,

    One error for example is that the import file excel is trying to retrieve does not exist, in which case I have to press OK.
    The exact error message is:
    "The internet address *internet address* is not valid"
    and there's an "OK" button to press and continue.

  • #33292

    Participant
    Points: 1
    Rank: Member

    No errors here to.
    What's in the excel files?

The topic ‘Ignoring warning/error popup messages for Excel script’ is closed to new replies.