Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling Procedures by running a single macro in Excel

Posted on 2012-03-23
7
Medium Priority
?
273 Views
Last Modified: 2012-03-23
I would like my staff to be able to run a single macro (Analysis_Main) which executes a series of procedures.  I only want the MainMacro to be visible in the macro window.

Here's the main sub:

Public Sub Analysis_Main()
Call A_auto_load
Call B_DateFormat
Call CH_Status_to_Posted
Call D_Analyze_newest_and_prior_tabs
Call F_ToDTRpaste
End Sub


Here's the error that I get.  "Compile error:  Sub or Function not defined." because Excel needs the Private subs in the same module, I guess.  If I make them "Public"  then they run but display in the macro window.

Should I make the subs "Public" or "Private" and where should I put them in relation to the various modules?  Is there another setting that I'm missing here to accomplish what I want to do?

Thanks for your help.
0
Comment
Question by:thutchinson
[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
  • 4
  • 3
7 Comments
 
LVL 42

Accepted Solution

by:
dlmille earned 2000 total points
ID: 37759531
Put the subs to be called in the same module as your main sub, and they can remain private, but within scope of your main  module.

Another trick is to create an optional parameter in the sub declaration, then they wouldn't be visible and can be public in another module - I don't necessarily condone this for no other purpose, but one side effect is they can't be called from the tools->macros or developer->macros menu option.

Chip Pearson on scoping: http://www.cpearson.com/excel/scope.aspx

Cheers,

Dave
0
 

Author Comment

by:thutchinson
ID: 37759544
OK, I thought I was missing something.  

Do you have any tricks on how to find these procedures later after they are buried down deep in thousands of lines of code within a single module?
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37759547
Ah - in the VBA editor, there are two pulldown menus where your code is at the top.  On the right side, you can pull down to find all functions and subroutines.

Dave
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:thutchinson
ID: 37759548
When should I consider creating a new module?
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37759551
While there are # lines limits, etc., they're pretty big for most development.

Personally, I always create new modules when I'm on to a new "topic", when I have a bunch of miscellaneous functions, and I tend to name my modules base on the topic they handle.

You might google around or ask a new question on just this topic, as the E-E experts will give you a good list of answers based on their experience, as well.

Dave
0
 

Author Comment

by:thutchinson
ID: 37759553
Oh, that's right.  I saw that menu before.  I didn't use it because I was always putting separate stuff in different modules so only one thing was showing in the drop-down.

I see now.
0
 

Author Closing Comment

by:thutchinson
ID: 37759558
Thanks for the overview, Dave.  I appreciate it.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

688 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