Solved

Calling Procedures by running a single macro in Excel

Posted on 2012-03-23
7
260 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 41

Accepted Solution

by:
dlmille earned 500 total points
Comment Utility
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
Comment Utility
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 41

Expert Comment

by:dlmille
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:thutchinson
Comment Utility
When should I consider creating a new module?
0
 
LVL 41

Expert Comment

by:dlmille
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the overview, Dave.  I appreciate it.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now