I have a worksheet with the "tab" name of "Rpt_Group". I also renamed its code name to shData. When I use VBA to activate the worksheet using "Rpt_Group" it runs fine. But when I use the code name I get an error message
"subscript out of range.
This works: WBA.Worksheets("Rpt_Group").Activate
This does not work: WBA.Worksheets("shData").Activate
This does not work: WBA.shData.Activate
Dim WBA As Workbook
'Open the desired workbook
Set WBA = Workbooks.Open(Filename:="path & file name")
'Activate the desired worksheet
WBA.Worksheets("Rpt_Group").Activate 'this works
This does not work: WBA.Worksheets("shData").Activate
This does not work: WBA.shData.Activate
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…