Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Variables - simple question

Can I dim a public variable anywhere in a project or does it have to be in a
module?

I have a variable in my workbook_open event. I now need to use this
variable elsewhere in my project. What is the proper way to do this?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Variables - simple question

Public declarations are made in the declarations section of a module - which
is at the top (see the left dropdown at the top of the module).

In General:
If you want the variable visible to all components of the project, then you
need to declare it in a general module (insert=Module). Don't declare it
in any of the Class modules like ThisWorkbook, Sheet Modules or Userform
modules.

--
Regards,
Tom Ogilvy


Squid wrote in message
news:awqXb.33427$yE5.114887@attbi_s54...
Can I dim a public variable anywhere in a project or does it have to be in

a
module?

I have a variable in my workbook_open event. I now need to use this
variable elsewhere in my project. What is the proper way to do this?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Variables - simple question

Squid,

Declare the variable in a standard code module, not the
ThisWorkbook module, above and outside of any procedure.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Squid" wrote in message
news:awqXb.33427$yE5.114887@attbi_s54...
Can I dim a public variable anywhere in a project or does it

have to be in a
module?

I have a variable in my workbook_open event. I now need to use

this
variable elsewhere in my project. What is the proper way to do

this?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Variables - simple question

Another approach is to create a public property in the ThisWorkbook
code module and persist its value in a private variable declared the
ThisWorkbook general declarations. You can then refer to it from other
open workbooks e.g.

Application.Workbooks(2).MyProperty

--

"Chip Pearson" wrote in message ...
Squid,

Declare the variable in a standard code module, not the
ThisWorkbook module, above and outside of any procedure.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Squid" wrote in message
news:awqXb.33427$yE5.114887@attbi_s54...
Can I dim a public variable anywhere in a project or does it

have to be in a
module?

I have a variable in my workbook_open event. I now need to use

this
variable elsewhere in my project. What is the proper way to do

this?


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
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
general question about variables integreat Excel Discussion (Misc queries) 2 May 20th 06 07:29 AM
Simple Simple Excel usage question BookerW Excel Discussion (Misc queries) 1 June 23rd 05 10:06 PM
simple question, hopefully a simple answer! Matt B Excel Programming 5 January 13th 04 08:43 PM
Question about scoping variables TBA[_2_] Excel Programming 1 January 8th 04 01:47 AM


All times are GMT +1. The time now is 04:58 PM.

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

About Us

"It's about Microsoft Excel"