Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Global Variables in Excel VBA

I have an excel program, heavily driven by menus and buttons with
various entry-points and exits.

I am however attempting to create a global variable that could be used
to store and access data, regardless of the entry/exit point used.

Use of the public command would create a global variable which would to
this. However, given the fact that a user may come in at any point
(depending on what button or menu they use), there is no obvious way to
create a global variable.

Is there a way to actually create a global variable - that could be
used regardless of what a user presses?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Global Variables in Excel VBA

I don't completely understand your question. If you declare a Public (the
new term for "Global"), in a standard code module (not in a object module
like a Userform or Class module), you can write/read to and from that
variable from any procedure in any module in the project. E.g.,

Public MyVar As Variant

Beyond that, I don't understand what your dilemma is.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)


wrote in message
ups.com...
I have an excel program, heavily driven by menus and buttons with
various entry-points and exits.

I am however attempting to create a global variable that could be used
to store and access data, regardless of the entry/exit point used.

Use of the public command would create a global variable which would to
this. However, given the fact that a user may come in at any point
(depending on what button or menu they use), there is no obvious way to
create a global variable.

Is there a way to actually create a global variable - that could be
used regardless of what a user presses?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 122
Default Global Variables in Excel VBA

If worst comes to worst, you could always store any such data in the
workbook itself. Something akin to a "Settings" worksheet.

On Nov 5, 7:59 pm, wrote:

Is there a way to actually create a global variable - that could be
used regardless of what a user presses?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Global Variables in Excel VBA

If worst comes to worst, you could always store any such data in the
workbook itself.


I wouldn't characterize that technique as something one would do if "worst
comes to worst". I've done that on more than a few occasions when I needed
to store a value and couldn't run the risk of globals getting wiped out by
the user monkeying around in the VBE. If you need to be certain that a
variable won't be wiped out of memory, you need to store it in a worksheet
cell, a defined name, or the registry. As long as you're not storing huge
number of variables in a sheet, to the point where performance would be
noticeably degraded, there's really nothing wrong at all with storing temp
data in a worksheet. Just make the sheet xlVeryHidden so the user can't
screw it up, and its a perfectly legitimate technique.



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)


"Randy Harmelink" wrote in message
oups.com...
If worst comes to worst, you could always store any such data in the
workbook itself. Something akin to a "Settings" worksheet.

On Nov 5, 7:59 pm, wrote:

Is there a way to actually create a global variable - that could be
used regardless of what a user presses?






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Global Variables in Excel VBA

Put this in a module:

Public Const GLOBAL_VAR as String

Then GLOBAL_VAR is available in any module.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Global Variables in Excel VBA

See Tom Ogilvy's response to my question "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"

Regards,
Stefi


ezt *rta:

I have an excel program, heavily driven by menus and buttons with
various entry-points and exits.

I am however attempting to create a global variable that could be used
to store and access data, regardless of the entry/exit point used.

Use of the public command would create a global variable which would to
this. However, given the fact that a user may come in at any point
(depending on what button or menu they use), there is no obvious way to
create a global variable.

Is there a way to actually create a global variable - that could be
used regardless of what a user presses?


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
Global variables Ed Excel Programming 4 August 7th 06 04:00 AM
Global Variables [email protected] Excel Programming 0 July 7th 06 10:53 AM
global variables Mike Archer Excel Programming 4 May 3rd 06 07:33 PM
global variables [email protected] Excel Programming 3 November 16th 05 11:44 PM
Global Variables Ernst Guckel[_4_] Excel Programming 2 May 7th 05 11:10 PM


All times are GMT +1. The time now is 11:20 AM.

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"