locked
Excel switch worksheets RRS feed

  • Question

  • Hi.  I need to open a workbook and switch to a worksheet.

    This is what I have.  I can not get the dashboard worksheet to be active.  

     $xl = New-Object -ComObject "Excel.Application"

    $wb = $xl.Workbooks.Open("C:\Scripts\ReportingProject\MailboxSize.xlsx")

    $xl.Visible = $True

    $wb.activate

    $wb.worksheets.("Dashboard").Activate 



    Thanks, Matt Alter

    Tuesday, May 6, 2014 9:16 PM

Answers

  • Sorry - I missed this:

     $wb.worksheets.Item("Dashboard").Activate()

    You need to use the Item method to access the sheet by name.  You also need to use parens on Activate() because it, too, is a method.


    ¯\_(ツ)_/¯

    • Marked as answer by Bill_Stewart Wednesday, May 7, 2014 2:36 PM
    Tuesday, May 6, 2014 9:33 PM

All replies

  • What is the question?  Are you getting an error?


    ¯\_(ツ)_/¯

    Tuesday, May 6, 2014 9:29 PM
  • Sorry - I missed this:

     $wb.worksheets.Item("Dashboard").Activate()

    You need to use the Item method to access the sheet by name.  You also need to use parens on Activate() because it, too, is a method.


    ¯\_(ツ)_/¯

    • Marked as answer by Bill_Stewart Wednesday, May 7, 2014 2:36 PM
    Tuesday, May 6, 2014 9:33 PM
  • Thanks, that was it.


    Thanks, Matt Alter

    Wednesday, May 7, 2014 12:54 PM