+ Reply to Thread
Results 1 to 2 of 2

determine the active workbook containing a specific sheet

  1. #1
    Valeria
    Guest

    determine the active workbook containing a specific sheet

    Dear experts,
    I am trying to determine within my open workbooks the one that contains the
    sheet "Instructions", workbook that I would like to activate.
    My code (not working!) is the following:

    i = 0
    Do
    i = i + 1
    Loop Until IsError(Workbooks(i).Worksheets("Instructions")) = False
    Workbooks(i).Activate
    WBReport = Workbooks(i).Name

    Could you please help me?
    Many thanks!
    Best regards,

    --
    Valeria

  2. #2
    K Dales
    Guest

    RE: determine the active workbook containing a specific sheet

    Function ActivateInstructions() As String
    ' Will activate the worksheet "Instructions"
    ' Returns the name of the workbook containing the sheet "Instructions"
    ' Note: If there happens to be more than one workbook with a sheet called
    "Instructions" this will activate and return the one opened most recently.
    ' If no book contains a sheet called "Instructions" function returns an
    empty string

    Dim WB As Workbook
    ActivateInsrtuctions = ""
    For Each WB In Application.Workbooks
    On Error GoTo NoInstructions
    WB.Worksheets("Instructions").Activate
    ActivateInstructions = WB.Name
    NoInstructions:
    On Error GoTo 0
    Next WB
    End Function

    --
    - K Dales


    "Valeria" wrote:

    > Dear experts,
    > I am trying to determine within my open workbooks the one that contains the
    > sheet "Instructions", workbook that I would like to activate.
    > My code (not working!) is the following:
    >
    > i = 0
    > Do
    > i = i + 1
    > Loop Until IsError(Workbooks(i).Worksheets("Instructions")) = False
    > Workbooks(i).Activate
    > WBReport = Workbooks(i).Name
    >
    > Could you please help me?
    > Many thanks!
    > Best regards,
    >
    > --
    > Valeria


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1