Solved

color defined globally vba

Posted on 2012-03-20
3
232 Views
Last Modified: 2012-08-14
How do I set global variable in my Excel vba project and how can I call it from any module,sheet,form or class.

Is Gobalscope a term associated with setting these variables. Can I define an entire function globally? Please post an example if possible.

The project is to store or call colors defined in the vba proj (chart creation)that can be defined globally in a page so I dont have to change them on each page individually and can alter them in one location itself.
0
Comment
Question by:Moizsaif123
3 Comments
 
LVL 9

Accepted Solution

by:
armchair_scouse earned 500 total points
ID: 37741554
Make the variable/constant public so that all of your code can see it (it's available to all module/forms).  For example, I create a module called basGlobal when developing in VBA that holds all of my global variables and constants.  I prefix my globals with a 'g' and constants with a 'c'. Examples:

Global Constant:            Public Const  gcPI = 3.14159623
Global Variable:             Public gstrApplicationName As String = "My Application"

There's more explanation here: http://support.microsoft.com/kb/141693
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37741592
Here is a sample.
4.zip
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 37743164
Note that depending on what version of VBA you're using you may not be able to do this:

Public gstrApplicationName As String = "My Application"

and you may have to do the following instead

Public gstrApplicationName As String
gstrApplicationName = "My Application"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now