Public variable

E

Eric

Hello,

I am setting up a public variable in the declaration section of my module
(Public Authorized_Machine as string)
I initialize the variable right in the Auto_open() sub expecting ths
variable and its value to be available to all the procedures in my module,
but it does not work.
A simple "MsgBox Authorized_Machine" (in a seperate procedure) shows the
variable empty...

What am I doing wrong?

Thank you.

Eric
 
L

Leith Ross

Hello,

I am setting up a public variable in the declaration section of my module
(Public Authorized_Machine as string)
I initialize the variable right in the Auto_open() sub expecting ths
variable and its value to be available to all the procedures in my module,
but it does not work.
A simple "MsgBox Authorized_Machine" (in a seperate procedure) shows the
variable empty...

What am I doing wrong?

Thank you.

Eric

Hello Eric,
The Auto_Open, Auto_Close, Auto_Activate, and Auto_Deactivate macros
are provided for backward compatability. You should be using
Workbook_Open instead of Auto_Open. Place your Public varaiable in the
Declarations section of ThisWorkbook and placce your Auto_Open code
in the Workbook_Open procedure.

Sincerely,
Leith Ross
 
J

Jim Cone

Eric,
1. An Auto_Open sub must be in a standard module, not in the
ThisWorkbook module or a sheet module.
2. If you are opening the workbook using code then any Auto_xxx
subs will not run. Your have to use the RunAutoMacros method.
3. The public declaration of the variable should be in standard module.
4. The Workbook_Open event sub could also be used to initialize the variable.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"Eric" <[email protected]>
wrote in message
Hello,
I am setting up a public variable in the declaration section of my module
(Public Authorized_Machine as string)
I initialize the variable right in the Auto_open() sub expecting ths
variable and its value to be available to all the procedures in my module,
but it does not work.
A simple "MsgBox Authorized_Machine" (in a seperate procedure) shows the
variable empty...
What am I doing wrong?
Thank you.
Eric
 
G

Gary Keramidas

i don't have any luck when i have this in thisworkbook:
Option Explicit
Public RptFlag As Boolean
Public cnt As Long
Public iRow As Long
Public iMonth As Long
Public eMonth As Long

fails to compile because it says the variables aren't defined.
 
E

Eric

Thank you Leith.

Leith Ross said:
Hello Eric,
The Auto_Open, Auto_Close, Auto_Activate, and Auto_Deactivate macros
are provided for backward compatability. You should be using
Workbook_Open instead of Auto_Open. Place your Public varaiable in the
Declarations section of ThisWorkbook and placce your Auto_Open code
in the Workbook_Open procedure.

Sincerely,
Leith Ross
 
E

Eric

I had this too...

Eric

Gary Keramidas said:
i don't have any luck when i have this in thisworkbook:
Option Explicit
Public RptFlag As Boolean
Public cnt As Long
Public iRow As Long
Public iMonth As Long
Public eMonth As Long

fails to compile because it says the variables aren't defined.
 
B

Bob Phillips

Should be in a standard module, not ThisWorkbook.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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