Originally Posted by
Welshgasman
So have you walked through the code line by line?
I have walked through the code. When I use the .Name everything works just fine. The block of code looks like this:
Code:
For Each wks In wkb.Worksheets
Debug.Print wks.Name
If wks.Name = "Sheet2" Then
Set wks = xl.Worksheets(wks.Name)
wks.Select
Exit For
End If
Next wks
When I change out the .name with .codename property nothing appears in the immediate window when using debug.print...I'm guessing since nothing is assigned to the property, it errors out once hitting the wks.Range("A2")... since nothing is assigned as the worksheet. The block of code looks like this:
Code:
For Each wks In wkb.Worksheets
Debug.Print wks.CodeName
If wks.CodeName = "Sheet2" Then
Set wks = xl.Worksheets(wks.Name)
wks.Select
Exit For
End If
Next wks
I decided to use the .codename property after reading similar threads like Gicu recommended. What I don't understand is I swear I had the .codename property working in my code before and I was verifying it under the debug.print property but now nothing registers anymore. I'm not sure if anyone has had similar problems or has had experience troubleshooting something like this?