Solved

color defined globally vba

Posted on 2012-03-20
3
241 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 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 48

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

687 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