none
Activating a Specific Worksheet from VBA within a MS Project Module RRS feed

  • Question

  • Hi All

    I am trying to activate a Worksheet from within a VBA Module in a MS Project Plan.  The code snippet where I have the issue is shown belos for information:

    Set xlApp = CreateObject("Excel.Application")
        xlApp.Visible = True
        Workbooks.Open FileName:=xlFilename
        xlApp.ActiveWorkbook.Sheets(Workstream).Activate

    The workbook opens fine but I cannot find out how to activate the specific worksheet (name is in the "Workstream" variable.

    Any help/advice appreciated.

    Kind regards

    Tony


    TKHussar

    Monday, August 10, 2015 8:11 AM

Answers

  • Hi Tony

    I can't test this in Project, but it should work the same from any non-Excel VBA project... The following works fine for me

    Sub StartExcelActivateWS()
        Dim xl As Excel.Application
        Dim wb As Excel.Workbook
        Dim ws As Excel.Worksheet
        
        Set xl = New Excel.Application
        xl.Visible = True
        xl.UserControl = True
        Set wb = xl.Workbooks.Open("FilePathANdName")
        Set ws = wb.Worksheets("Sheet1")
        ws.Activate
    End Sub
    


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by TKHussar Monday, August 10, 2015 3:56 PM
    Monday, August 10, 2015 3:52 PM
    Moderator

All replies

  • Hi Tony

    I can't test this in Project, but it should work the same from any non-Excel VBA project... The following works fine for me

    Sub StartExcelActivateWS()
        Dim xl As Excel.Application
        Dim wb As Excel.Workbook
        Dim ws As Excel.Worksheet
        
        Set xl = New Excel.Application
        xl.Visible = True
        xl.UserControl = True
        Set wb = xl.Workbooks.Open("FilePathANdName")
        Set ws = wb.Worksheets("Sheet1")
        ws.Activate
    End Sub
    


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by TKHussar Monday, August 10, 2015 3:56 PM
    Monday, August 10, 2015 3:52 PM
    Moderator
  • Hi Cindy

    Many thanks.  That works fine.

    Kind regards

    Tony


    TKHussar

    Monday, August 10, 2015 3:55 PM