vbaexcelvbe

Worksheet names in VBE


I've noticed that my workbook has two different names for each component in the VBE. What is the difference between name1 and name2? Which one should I refer to, so I will be sure my macro will work?

enter image description here


Solution

  • Control is the code name of the sheet, whereas Plan 1 is the tab name of the sheet. The latter can be easily changed by the user so it's safer to use the codename if you can - for example, referring to:

    control.range("A1:A10")
    

    rather than:

    sheets("Plan 1").Range("A1:A10")
    

    Note that you cannot use sheet codenames to refer to sheets in workbooks other than the one containing the code unless you set a reference to the project of that workbook, or use a function that loops through each sheet in the other workbook testing the codename property of each.