Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Complete list of characters valid in a VBA variable name?

734 views
Skip to first unread message

John Gunther

unread,
Mar 8, 2006, 9:29:55 PM3/8/06
to
I need to know all of the characters than can be part of a valid VBA
variable name.

Dim çà as Integer

This VBA line compiles fine, so ç and à are acceptable.
abcdefghijklmnopqrstuvwxyz are clearly OK too. 0123456789 and _ are OK
as long as they don't come first.

But what I need is a complete list. Does anyone have it, or know where
I can get it?

Why do I need this? See http://invisiblebasic.sourceforge.net/, an open
source Excel/VBA source obfuscation utility--I need a list of such
characters so I can properly recognize variable names regardless of if
the VBA code is created by French or English or ... speaking VBA
coders.

I searched around but could not find this list anywhere...please help.

John

Tony Jollans

unread,
Mar 9, 2006, 2:36:56 AM3/9/06
to
The actual characters depend on your code page but I believe any character
in the range 128-255 is allowable. They are also case insensitive so

Dim çà as Integer

is the same as

Dim ÇÀ as Integer

--
Enjoy,
Tony


"John Gunther" <johncurt...@yahoo.com> wrote in message
news:1141871394....@i40g2000cwc.googlegroups.com...

John Gunther

unread,
Mar 9, 2006, 10:57:28 PM3/9/06
to
I was sure you must be wrong because I figured some of those characters
look so weird that they must have been excluded...so I wrote this test
program:

Sub Test_128_to_255()

Dim € ,ƒ,,...†‡ˆ‰Š‹Œ
Dim Ž ''""·--˜™š›
Dim œ žŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³
Dim ´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌ
Dim ÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßà
Dim áâãäåæçèéêëìíîïðñò
Dim óôõö÷øùúûüýþÿ

€ ,ƒ,,...†‡ˆ‰Š‹Œ = 1
Ž ''""·--˜™š› = 2
œ žŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³ = 3
´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌ = 4
ÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßà = 5
áâãäåæçèéêëìíîïðñò = 6
óôõö÷øùúûüýþÿ = 7

Debug.Print € ,ƒ,,...†‡ˆ‰Š‹Œ
Debug.Print Ž ''""·--˜™š›
Debug.Print œ žŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³
Debug.Print ´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌ
Debug.Print ÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßà
Debug.Print áâãäåæçèéêëìíîïðñò
Debug.Print óôõö÷øùúûüýþÿ

End Sub

This uses all of the characters in the range you mentioned and compiles
and runs (printing 1, 2, ... 7) just fine.

Thanks for the info....I never would have guessed that, say, ©,
represents a valid VBA variable name.

Any sense if this character range will remain valid in future VBA
versions? I don't want to generate obfuscated variables using such
characters only to find MS has changed the rules later by excluding
some of the ones no human language ever uses in real words, thus
breaking previously obfuscated code. But using the full character range
you mentioned will make the obfuscated code smaller--hence (a little)
better.

John

Tony Jollans

unread,
Mar 10, 2006, 2:32:50 AM3/10/06
to
I think it unlikely that code that works today will fail tomorrow, as it
were, but have failed to find any written evidence supporting the validity
of these characters. Locale-specific code pages have, essentially, been
superseded by unicode so I don't expect any changes in this area but whether
what amounts to legacy support will continue is anybody's guess.

--
Enjoy,
Tony


"John Gunther" <johncurt...@yahoo.com> wrote in message

news:1141963048.3...@i40g2000cwc.googlegroups.com...


> I was sure you must be wrong because I figured some of those characters
> look so weird that they must have been excluded...so I wrote this test
> program:
>
> Sub Test_128_to_255()
>

> Dim ? ,f,,...??^?S > Dim Z ''""·--~Ts>
> Dim o zY ¡¢£¤¥¦§¨©ª«¬­®¯°±²³


> Dim ´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌ
> Dim ÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßà
> Dim áâãäåæçèéêëìíîïðñò
> Dim óôõö÷øùúûüýþÿ
>

> ? ,f,,...??^?S > Z ''""·--~Ts> = 2
> o zY ¡¢£¤¥¦§¨©ª«¬­®¯°±²³ = 3


> ´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌ = 4
> ÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßà = 5
> áâãäåæçèéêëìíîïðñò = 6
> óôõö÷øùúûüýþÿ = 7
>

> Debug.Print ? ,f,,...??^?S > Debug.Print Z ''""·--~Ts>
> Debug.Print o zY ¡¢£¤¥¦§¨©ª«¬­®¯°±²³

Klaus Linke

unread,
Mar 10, 2006, 9:14:36 AM3/10/06
to
It could also be a bit problematic if you'd ever want to use the macro
internationally.
It would likely still run, but since those upper-ASCII characters are
different in different code pages, the variable names would read
differently.

Klaus


"Tony Jollans" <My Forename at My Surname dot com> schrieb im Newsbeitrag
news:%231oAuTB...@TK2MSFTNGP09.phx.gbl...

Klaus Linke

unread,
Mar 10, 2006, 8:55:48 PM3/10/06
to
> It would likely still run, but since those upper-ASCII characters are
> different in different code pages, the variable names would read
> differently.

Just read in some other newsgroup how it took some French guy ages to find
that é is problematic in the Japanese version.

:-/ Klaus


Tony Jollans

unread,
Mar 10, 2006, 9:31:01 PM3/10/06
to
Interesting. I have never seen anything on this documented anywhere - and I
can easily imagine that code page differences could have an effect.

--
hť}
"Klaus Linke" <in...@fotosatz-kaufmann.de> wrote in message
news:uKgvJ6KR...@TK2MSFTNGP09.phx.gbl...

John Gunther

unread,
Mar 11, 2006, 8:34:09 PM3/11/06
to
Tony, Klauss

Very interested to hear the report that "é is problematic in the
Japanese version".

Based on our discussions, I'm now planning to modify Invisible Basic so
that it RECOGNIZES 128-255 as valid characters in VBA identifiers if
they appear in the original (unobfuscated) code, but I'll play it safe
and only allow, a-z, 0-9 _ in GENERATED obfuscated variable names. A
bit more work to make this distinction, and it makes the obfuscated
code a little bigger, but since I can't be 100% sure introducing such
characters into already working code will not break it, this seems the
wisest course.

Your comments and information were very helpful in resolving this
problem so (unless you have a problem with me doing so) I'll mention
your assistance in documentation for the next Invisible Basic release.

John

0 new messages