N
Nile_Hef
How does Excel enumerate the Names collection?
We're getting spreadsheets from overseas offices with named ranges that we
cannot access by name, nor delete, rename or hide... Not even when I
enumerate the names collection, or loop though it by ordinal number:
For each MyName in Thisworkbook.Names
MyName.delete
Next MyName
or the alternative:
For i = Thisworkbook.Names.Count to 1 Step - 1
Thisworkbook.Names(i).Delete
Next i
As soon as either loop hits the offending item in the collection, VBA raises
the error "That name is not valid".
Inspecting the names collection using the 'Insert; Names...' dialog from the
worksheet menubar reveals that the name contains non-standard characters
which display as odd squiggles and squares on a UK- or US-locale PC. Possibly
they are umlauts, accented vowels, or copied from Cyrillic documents.
Changing the locale to Sweden, Germany or Japan doesn't help. (Japan was a
wild guess - we know it's the wrong language, but the codepage is so large
that surely there's no such thing as an invalid character...).
All suggestions welcome*
Also... Some idea of how Excel actually stores that collection would be
interesting. Surely it's got some kind of internal ordinal; I can't believe
that it's indexed by hashing the unicode string from the name.
* The suggection 'Nuke the site from orbit' has been carefully considered
but was found to be impracticable for reasons of health & safety.
We're getting spreadsheets from overseas offices with named ranges that we
cannot access by name, nor delete, rename or hide... Not even when I
enumerate the names collection, or loop though it by ordinal number:
For each MyName in Thisworkbook.Names
MyName.delete
Next MyName
or the alternative:
For i = Thisworkbook.Names.Count to 1 Step - 1
Thisworkbook.Names(i).Delete
Next i
As soon as either loop hits the offending item in the collection, VBA raises
the error "That name is not valid".
Inspecting the names collection using the 'Insert; Names...' dialog from the
worksheet menubar reveals that the name contains non-standard characters
which display as odd squiggles and squares on a UK- or US-locale PC. Possibly
they are umlauts, accented vowels, or copied from Cyrillic documents.
Changing the locale to Sweden, Germany or Japan doesn't help. (Japan was a
wild guess - we know it's the wrong language, but the codepage is so large
that surely there's no such thing as an invalid character...).
All suggestions welcome*
Also... Some idea of how Excel actually stores that collection would be
interesting. Surely it's got some kind of internal ordinal; I can't believe
that it's indexed by hashing the unicode string from the name.
* The suggection 'Nuke the site from orbit' has been carefully considered
but was found to be impracticable for reasons of health & safety.