ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Workbook-level public variables (https://www.excelbanter.com/excel-programming/329009-workbook-level-public-variables.html)

Stefi

Workbook-level public variables
 
Hi all,
How can I declare a public variable (e.g. in Workbook_open event) that will
be valid in all other regular and event modules in the workbook?
Stefi


Tom Ogilvy

Workbook-level public variables
 
declare it in a general module and initialize it in from any module

General Module:

Public MyVar as Long

in the ThisWorkbook Module

Private Sub Workbook_Open()
MyVar = 6
end Sub

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
Hi all,
How can I declare a public variable (e.g. in Workbook_open event) that

will
be valid in all other regular and event modules in the workbook?
Stefi




Bob Phillips[_7_]

Workbook-level public variables
 
Stefi,

Declare it in a normal code module, not ThisWorkbook

--
HTH

Bob Phillips

"Stefi" wrote in message
...
Hi all,
How can I declare a public variable (e.g. in Workbook_open event) that

will
be valid in all other regular and event modules in the workbook?
Stefi




Stefi

Workbook-level public variables
 
It seems to me a bottom-up logic (why can't I declare it public in the Sub
Workbook_Open() where I already know I will need it as public) but it works.
Thanks!
Stefi

Tom Ogilvy ezt *rta:

declare it in a general module and initialize it in from any module

General Module:

Public MyVar as Long

in the ThisWorkbook Module

Private Sub Workbook_Open()
MyVar = 6
end Sub

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
Hi all,
How can I declare a public variable (e.g. in Workbook_open event) that

will
be valid in all other regular and event modules in the workbook?
Stefi





Tom Ogilvy

Workbook-level public variables
 
You can do that, but then you have to refer to it like this

msgbox ThisWorkbook.MyVar

Since ThisWorkbook is actually a class module, you are creating a property
of the ThisWorkbook class.

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
It seems to me a bottom-up logic (why can't I declare it public in the Sub
Workbook_Open() where I already know I will need it as public) but it

works.
Thanks!
Stefi

"Tom Ogilvy" ezt rta:

declare it in a general module and initialize it in from any module

General Module:

Public MyVar as Long

in the ThisWorkbook Module

Private Sub Workbook_Open()
MyVar = 6
end Sub

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
Hi all,
How can I declare a public variable (e.g. in Workbook_open event) that

will
be valid in all other regular and event modules in the workbook?
Stefi







Stefi

Workbook-level public variables
 
Is creating a variable considered as creating a property, or otherwise: is a
variable declared in a class module a property of the class?


Tom Ogilvy ezt *rta:

You can do that, but then you have to refer to it like this

msgbox ThisWorkbook.MyVar

Since ThisWorkbook is actually a class module, you are creating a property
of the ThisWorkbook class.

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
It seems to me a bottom-up logic (why can't I declare it public in the Sub
Workbook_Open() where I already know I will need it as public) but it

works.
Thanks!
Stefi

"Tom Ogilvy" ezt *rta:

declare it in a general module and initialize it in from any module

General Module:

Public MyVar as Long

in the ThisWorkbook Module

Private Sub Workbook_Open()
MyVar = 6
end Sub

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
Hi all,
How can I declare a public variable (e.g. in Workbook_open event) that
will
be valid in all other regular and event modules in the workbook?
Stefi








Tom Ogilvy

Workbook-level public variables
 
That is pretty much what I said. (if you declare the variable Public is it
accessible outside the class - so it is a public property. if it isn't
declared as public, then it is a hidden property. This is for variables
declared in the declarations section).

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
Is creating a variable considered as creating a property, or otherwise: is

a
variable declared in a class module a property of the class?


"Tom Ogilvy" ezt rta:

You can do that, but then you have to refer to it like this

msgbox ThisWorkbook.MyVar

Since ThisWorkbook is actually a class module, you are creating a

property
of the ThisWorkbook class.

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
It seems to me a bottom-up logic (why can't I declare it public in the

Sub
Workbook_Open() where I already know I will need it as public) but it

works.
Thanks!
Stefi

"Tom Ogilvy" ezt rta:

declare it in a general module and initialize it in from any module

General Module:

Public MyVar as Long

in the ThisWorkbook Module

Private Sub Workbook_Open()
MyVar = 6
end Sub

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
Hi all,
How can I declare a public variable (e.g. in Workbook_open event)

that
will
be valid in all other regular and event modules in the workbook?
Stefi










Stefi

Workbook-level public variables
 
Now I see, thank you!

Tom Ogilvy ezt *rta:

That is pretty much what I said. (if you declare the variable Public is it
accessible outside the class - so it is a public property. if it isn't
declared as public, then it is a hidden property. This is for variables
declared in the declarations section).

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
Is creating a variable considered as creating a property, or otherwise: is

a
variable declared in a class module a property of the class?


"Tom Ogilvy" ezt *rta:

You can do that, but then you have to refer to it like this

msgbox ThisWorkbook.MyVar

Since ThisWorkbook is actually a class module, you are creating a

property
of the ThisWorkbook class.

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
It seems to me a bottom-up logic (why can't I declare it public in the

Sub
Workbook_Open() where I already know I will need it as public) but it
works.
Thanks!
Stefi

"Tom Ogilvy" ezt *rta:

declare it in a general module and initialize it in from any module

General Module:

Public MyVar as Long

in the ThisWorkbook Module

Private Sub Workbook_Open()
MyVar = 6
end Sub

--
Regards,
Tom Ogilvy

"Stefi" wrote in message
...
Hi all,
How can I declare a public variable (e.g. in Workbook_open event)

that
will
be valid in all other regular and event modules in the workbook?
Stefi












All times are GMT +1. The time now is 12:16 PM.

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