In my workbook, the names of some of the worksheets sometimes change. However, the sheet "numbers" never change.
I need to assign the name of a particular sheet to a variable, so I can refer to the name later on in code. I figured out how to do it, using this:
However, my understanding is I should always put ThisWorkbook in front of any sheet reference, in case another workbook is open at the time the code is running, because I don't want the variable to be assigned the name of Sheet28 on the other open sheet (assuming it has one).
The way I would have thought to do it is like this:
Unfortunately, this causes an error. Is there a way to refer to the actual sheet "number" (like Sheet28 above) and ALSO tell it that I am referring to ThisWorkbook?
I need to assign the name of a particular sheet to a variable, so I can refer to the name later on in code. I figured out how to do it, using this:
Code:
Dim NameOfSheet As String
NameOfSheet = Sheet28.Name
However, my understanding is I should always put ThisWorkbook in front of any sheet reference, in case another workbook is open at the time the code is running, because I don't want the variable to be assigned the name of Sheet28 on the other open sheet (assuming it has one).
The way I would have thought to do it is like this:
Code:
NameOfSheet = ThisWorkbook.Sheet28.Name
Unfortunately, this causes an error. Is there a way to refer to the actual sheet "number" (like Sheet28 above) and ALSO tell it that I am referring to ThisWorkbook?