?
Solved

color defined globally vba

Posted on 2012-03-20
3
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
armchair_scouse earned 2000 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 49

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

765 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