Solved

Calling Procedures by running a single macro in Excel

Posted on 2012-03-23
7
270 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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 how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

626 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