Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Jun 2001
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Name property (2000)

    In XL 97 when you see a sheets properties, it has 2 NAME properties,
    one is (NAME) =Sheet1 and another NAME=Taxes for example. Now, how
    am I to know which NAME i'm accessing if I use vba to play around with
    it? Please advise.

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Name property (2000)

    The Name that is not in parenthesis is the name that displays on the sheet tab, and is the index that is used to locate the sheet in the Worksheets or Sheets collections, Like this:

    <pre> Worksheets("Texas").Range("A1").Select
    </pre>


    The (Name) in parenthesis is what Excel calls the Code Name and is an Object Name. You can use this name like any Object to reference the sheet, like this:

    <pre> Sheet1.Range("A1").Select
    </pre>

    Legare Coleman

  3. #3
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Silicon Valley, California, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Name property (2000)

    Not only that, you can change the code name in the property sheet in the VBE, to make your code more readable. For example, if you change it to shtTexas, then the following code works fine, and is nice and readable:

    <pre>shtTexas.Range("A1").Select
    </pre>


    Another advantage of using the code name is, the user can change the name on the tab to "Alabama" or what-not, and your code will still work.

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Name property (2000)

    And the disadvantage is that if the user deletes the sheet and creates a new one your code will no longer work.
    Legare Coleman

  5. #5
    3 Star Lounger
    Join Date
    Mar 2001
    Location
    Silicon Valley, California, USA
    Posts
    273
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Name property (2000)

    Touche. An important point I had not thought of. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •