Global variable

D

dhstein

I want to set a variable in a Workbook open event and then refer to it in
another module. I tried to set a Public variable in the Workbook code but
then the module doesn't recognize it. Any help is appreciated.
 
D

Dave Peterson

Put the variable in a General/standard/normal module.

Public MyVar as Variant '????

Then in the ThisWorkbook module:

Option Explicit
sub workbook_open()
myvar = "what ever you want"
end sub
 
D

dhstein

Thanks Dave.

Dave Peterson said:
Put the variable in a General/standard/normal module.

Public MyVar as Variant '????

Then in the ThisWorkbook module:

Option Explicit
sub workbook_open()
myvar = "what ever you want"
end sub
 

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