ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Global variable (https://www.excelbanter.com/excel-discussion-misc-queries/246992-global-variable.html)

dhstein

Global variable
 
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.

Dave Peterson

Global variable
 
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



dhstein wrote:

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.


--

Dave Peterson

dhstein

Global variable
 
Thanks Dave.

"Dave Peterson" wrote:

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



dhstein wrote:

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.


--

Dave Peterson
.



All times are GMT +1. The time now is 07:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com