

Of course, the syntax VBA has for handling an object or a string is completely different. Best, try this out in the VBE before you continue.

Pardon the play on words: If you change the TabName from "Sheet1" to "My Sheet", you could still refer to it by its CodeName Sheet1. Just like ActiveSheet always refers to the currently active sheet regardless of its name, Sheet1 always refers to "Sheet1", also regardless of its name. The difference between the TabName and CodeName is that the former is a name, in string format, while the latter is an object variable representing the worksheet. Both names can be modified in the Properties pane, too. It changes when you change the name on the tab and so does the Name property.

There you see the two names side by side, like Sheet1 (Sheet1), and the name set in parentheses is the TabName. In the Project Explorer pane developers of VBA, in their infinite wisdom, reversed the use of parentheses. Further down you see the Name property (without parentheses). When you look at the worksheet's properties in the VBE the very first property is called (Name), set in parentheses. The CodeName can only be set in the VB Editor properties. The TabName is set by the user from the worksheet UI. The CodeName is the name by which VBA refers to the sheet, the TabName is the name that the user gives to the tab. One is the CodeName, the other what I like to call the TabName. It's because of the way you refer to the worksheet.Įvery tab has two names.
