How to handle/disable or click OK on Pop Up while Converting excel to PDF

Viewed 36

I am running the following script and receiving the following POP UP to select printer, how can I handle it? Disable it or click OK

[1

param(
    [string]$filepath
)

$fileitem = Get-Item $filepath

try {

    $excel = New-Object -ComObject Excel.Application
    $excel.Visible = $false
    $excel.DisplayAlerts = $false

    $wb = $excel.Workbooks.Open($fileitem.FullName)

    # Generate path of save destination PDF file
    $pdfpath = $fileitem.DirectoryName + "\" + $fileitem.BaseName + ".pdf"

    # Save as PDF
    $wb.ExportAsFixedFormat([Microsoft.Office.Interop.Excel.XlFixedFormatType]::xlTypePDF, $pdfpath)

    $wb.Close()

    $excel.Quit()
}
0 Answers
Related