Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calling Procedures by running a single macro in Excel

Posted on 2012-03-23
7
Medium Priority
?
274 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
  • 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
Industry Leaders: 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

Industry Leaders: 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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

879 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