Macro to go to a specific sheet


I have a master file that I run a macro from. It opens all the files in a folder, do some updates, then save and close.

Right now the last tab the files is on when it's saved is on one sheet but I want it to be on another (summary) sheet.

I don't want to do the straightforward Sheets("Summary").Select in case people decide to rename the sheet. (I can tell them not to rename it but people tend not to follow directions that well.)

I don't want to "Protect Workbook" to prevent a rename as others might want to add other worksheets to do other work.

I can't use the sheet CodeName since I'm running the macro from the master file and the sheet is in another file.

Any other potential solutions?



Will the sheet always be in the same position in the workbook, as in always first or always last or always position 2?
don (rep: 1551) Jan 25, '19 at 4:45 pm
Add to Discussion



The reason you give for not being able to address sheets by their CodeName isn't correct. You can address any worksheet by either its name or code name. Try the code below while at least 2 workbooks are open. In my example the worksheet codenamed "Log" is not in ThisWorkbook.

Private Sub TestSheets()

    Dim Wb As Workbook
    Dim Ws As Worksheet

    For Each Wb In Application.Workbooks
        For Each Ws In Wb.Worksheets
            If Ws.CodeName = "Log" Then
                Debug.Print Ws.Name, Ws.CodeName
            End If
        Next Ws
    Next Wb
End Sub

So, knowing the CodeName, loop through all the sheets until you find the correct one and Select it.


Answer the Question

You must create an account to use the forum. Create an Account or Login