Solved

Calling Procedures by running a single macro in Excel

Posted on 2012-03-23
7
267 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 500 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

756 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