Respond to Excel prompts programatically

Welcome Forums General PowerShell Q&A Respond to Excel prompts programatically

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

 
Participant
2 months, 2 weeks ago.

  • Author
    Posts
  • #164346

    Participant
    Topics: 13
    Replies: 42
    Points: 243
    Rank: Participant

    I have a .xlsm file and I'm trying to convert it to a xlsx with the code below:

    $objExcel = New-Object -comobject excel.application
    $objExcel.Visible = $False
    $doc = $objExcel.WorkBooks.Open($path)
    $doc.SaveAs("$path\modified.xlsx",
    [Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook)
    $doc.close()
    
    $objExcel.Quit()
    $objExcel = $null

    The only problem is that excel prompts me with the GUI every time saying "The following features cannot be saved in macro-free workbooks...". I don't care though.

    How can I pipe a response to the prompt, as I would if there was a y/n confirmation in a cli command.

  • #164776

    Participant
    Topics: 13
    Replies: 42
    Points: 243
    Rank: Participant

    Bump

  • #165037

    Participant
    Topics: 23
    Replies: 154
    Points: 368
    Helping Hand
    Rank: Contributor

    i haven't tested, but you could try piping it to out-null

You must be logged in to reply to this topic.