Results 1 to 2 of 2

Thread: Excel VBA Names Collection

  1. #1

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126

    Excel VBA Names Collection

    Must be missing something simple here. Anyway, thought I would post it so someone can point me in the right direction.

    I am trying to use the value of a name which is stored in workbook A from Workbook B. The name is called "debugmode" and stores a True/False value.

    VB Code:
    1. Sub dosomething()
    2. If Workbooks("One").Names(debugmode).Name = True Then Cancel = True
    3. End sub
    I get a subscript out of range error.

    And then I tried a variation:
    If Workbooks("tbm_intro.xls").Names("debugmode") = True Then Cancel = True
    And got a type mismatch error.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    Names are stored at 2 levels - WorkBook and Worksheet.

    If set up manually, the ruling is that the first time a name is used it goes to Workbook level, if duplicated if goes to Worksheet level. This is controlled in VBA with Workbooks().Names.Add or Worksheets().Names Add. You should therefore probably be using something like :-

    If Workbooks("tbm_intro.xls").WorkSheets("Sheet1").Names("debugmode") .Value = True ...............
    Regards
    BrianB
    -------------------------------

Posting Permissions

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



Click Here to Expand Forum to Full Width