Show content of a variable instead of its name

L

LucaPri

I would like to solve a general problem in VBA (Word 2003, as well as Excel
2003):


Public Const Msg_01 = "Hello World"
Public Const Msg_02 = "Hello Universe"
.....

Sub Test()
MsgNo = "01"
X = "Msg_" & MsgNo

'How can I show now the content of the variable ("Hello world")
instead of the name ("Msg_01")?

MsgBox X

End Sub

Thanx in advance
LUCA
 
J

Jezebel

You can't. VBA can't manipulate the *names* of variables at all. Use an
array --

Private Msg(1 to 2) as string

Sub Initialize()

Msg(1) = "Hello World"
Msg(2) = "Hello Universe"

End Sub

:

MsgNo = 1
MsgBox Msg(MsgNo)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top