Solved

color defined globally vba

Posted on 2012-03-20
3
231 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 45

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…

744 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