Bring window (Excel) to foreground?

Welcome Forums General PowerShell Q&A Bring window (Excel) to foreground?

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

 
Participant
2 years ago.

  • Author
    Posts
  • #58714

    Participant
    Points: 0
    Rank: Member

    I'd like to be able to open an Excel file, then bring it to the foreground. I've seen older extensions, and old DLL-based approaches, but I don't want to get too far off the "beaten path". Using PowerShell 5, is there an easy way for my code below to bring the Excel file to the foreground? The code below works fine, but it leaves the opened Excel file visible, but in the background.

    $Excel = New-Object -ComObject Excel.Application
    $Workbook = $Excel.Workbooks.Open("MyExcelFile.xlsx")
    $Excel.Visible = $true
    $Excel.DisplayFullScreen = $true
    
  • #58715

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    Nope. PowerShell isn't a GUI automation tool. You'll need to dive into those old DLL things. Which you're already doing with that COM object for Excel :).

  • #58718

    Participant
    Points: 190
    Helping Hand
    Rank: Participant

    Is there a reason for doing it with com-object and Powershell?

    I mean if you want to automate stuff with Excel then you could have a look at my blog post regarding powershell and using the EPPlus .net library.

    psFredrik

  • #58811

    Participant
    Points: 27
    Rank: Member

    Take a look at this post: http://stackoverflow.com/questions/4993926/maximize-window-and-bring-it-in-front-with-powershell

    The accepted answer has a link to the PowerShell Community Extensions module which has a cmdlet to bring a window to the foreground.

The topic ‘Bring window (Excel) to foreground?’ is closed to new replies.