Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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









  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
public variables johnny Excel Discussion (Misc queries) 7 February 27th 08 03:44 PM
Public variables johnny Excel Discussion (Misc queries) 2 February 24th 08 05:05 AM
Public Variables Jerry McNabb Excel Discussion (Misc queries) 0 February 24th 08 01:26 AM
Public Variables ExcelMonkey[_190_] Excel Programming 5 February 21st 05 10:12 AM
Public Variables Les Gordon Excel Programming 2 November 11th 04 12:29 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"