Closed Thread
Results 1 to 14 of 14

Calling on a macro within a macro!

  1. #1
    mellowe
    Guest

    Calling on a macro within a macro!

    Hey All!!

    Quick Question - How do you call up a macro within a current macro? I
    have one big macro and I need it to jump to several other macros when
    it runs! Does it matter where the other macros are stored or is it
    better to have them all in one module?

    Help appreciated Thnx!


  2. #2
    Norman Jones
    Guest

    Re: Calling on a macro within a macro!

    Hi Mellowe,

    '=============>>
    Public Sub Main()
    'Your code
    Call One
    'your code
    End Sub
    '<<=============

    '=============>>
    Public Sub One()
    MsgBox "Hi from One"
    End Sub
    '<<=============

    > Does it matter where the other macros are stored or is it
    > better to have them all in one module?


    Unless there are a larger number of macros, they can be stored in a single
    module. However, for organisational reasons, it is usually better to store
    macros by type in different modules.

    ---
    Regards,
    Norman



    "mellowe" <[email protected]> wrote in message
    news:[email protected]...
    > Hey All!!
    >
    > Quick Question - How do you call up a macro within a current macro? I
    > have one big macro and I need it to jump to several other macros when
    > it runs! Does it matter where the other macros are stored or is it
    > better to have them all in one module?
    >
    > Help appreciated Thnx!
    >




  3. #3
    mellowe
    Guest

    Re: Calling on a macro within a macro!

    Thanks for the prompt reply Norman!!
    Sorry but I dont understand where does this piece of code goes ?
    I basically want start a macro that calls up in turn 5 other macros one
    after the other - I have stored these other five macros in 5 seperate
    modules under one Excel Sheet.
    Just not sure how to pull it all together! thnx


  4. #4
    CLR
    Guest

    Re: Calling on a macro within a macro!

    I use the following command line to call "outside" macros from within my
    main macro.....

    Application.Run ("YourFirstOutsideMacroName")
    Application.Run ("YourSecondOutsideMacroName")
    Application.Run ("YourThirdOutsideMacroName")
    Application.Run ("YourFourthOutsideMacroName")
    Application.Run ("YourFifthOutsideMacroName")

    These lines can be slpit up and placed at various places within your Main
    Macro at your desire.

    Vaya con Dios,
    Chuck, CABGx3



    "mellowe" wrote:

    > Thanks for the prompt reply Norman!!
    > Sorry but I dont understand where does this piece of code goes ?
    > I basically want start a macro that calls up in turn 5 other macros one
    > after the other - I have stored these other five macros in 5 seperate
    > modules under one Excel Sheet.
    > Just not sure how to pull it all together! thnx
    >
    >


  5. #5
    mellowe
    Guest

    Re: Calling on a macro within a macro!

    Sounds good! Will give it a go thnx!


  6. #6
    mellowe
    Guest

    Re: Calling on a macro within a macro!

    Sorry just a quick question on this - does it matter where the other 5
    macros are stored? Is it ok for them to be in different modules under
    the same Excel sheet? thnx?


  7. #7
    CLR
    Guest

    Re: Calling on a macro within a macro!

    It should not matter which module the called macros are stored in......I
    usually place them for my convienience of remembering where they are for
    future editing.

    Vaya con Dios,
    Chuck, CABGx3



    "mellowe" wrote:

    > Sorry just a quick question on this - does it matter where the other 5
    > macros are stored? Is it ok for them to be in different modules under
    > the same Excel sheet? thnx?
    >
    >


  8. #8
    Dave Peterson
    Guest

    Re: Calling on a macro within a macro!

    If the macros are in the same workbook, then you don't need application.run.

    You can just use:

    call Macro1
    call macro2
    call macro3

    And it sounds like these types of macros should not be in any worksheet
    module--or behind the ThisWorkbook module.

    They should be in just plain old General modules. The kind you get when you do
    Insert|Module.

    ===
    Application.run is very useful if you don't know the name of the macro that you
    need to call (it'll be determined by the code that's running). Or if the macro
    resides in another workbook.

    mellowe wrote:
    >
    > Sorry just a quick question on this - does it matter where the other 5
    > macros are stored? Is it ok for them to be in different modules under
    > the same Excel sheet? thnx?


    --

    Dave Peterson

  9. #9
    mellowe
    Guest

    Re: Calling on a macro within a macro!

    Thanks everyone for your help here!!...

    This is the situation: I have one worksheet that has a button to run my
    main macro - this macro opens up several other workbooks to initially
    complie a dataset.

    Once the dataset is completed I then need my main macro to run the
    additional 5 macros in order - they use the completed dataset (they
    also open up and change other workbooks' data) . All of these macros
    are in general plain modules, as you said Dave from: Insert|Module, and
    they are all behind one worksheet.

    So should I use Application. Run and name the macros or is the Call
    'Macro' option better?. Thnx again!


  10. #10
    SpookiePower
    Guest

    Re: Calling on a macro within a macro!

    Why do you use "Call" before the name of the macro ?

    I just write the name af the macro, and then it jumps to that macro.


  11. #11
    Dave Peterson
    Guest

    Re: Calling on a macro within a macro!

    It's not required. I just find it nicer (personal preference only).



    SpookiePower wrote:
    >
    > Why do you use "Call" before the name of the macro ?
    >
    > I just write the name af the macro, and then it jumps to that macro.


    --

    Dave Peterson

  12. #12
    Dave Peterson
    Guest

    Re: Calling on a macro within a macro!

    First, behind a worksheet means (to me) that they are behind one of the Sheet
    modules--not in a general module. If you really put them in a General module
    (Insert|module), then it's just a wording issue.

    It sure seems to me that there would be less things for excel to do if I Call a
    routine--rather than using application.run.



    mellowe wrote:
    >
    > Thanks everyone for your help here!!...
    >
    > This is the situation: I have one worksheet that has a button to run my
    > main macro - this macro opens up several other workbooks to initially
    > complie a dataset.
    >
    > Once the dataset is completed I then need my main macro to run the
    > additional 5 macros in order - they use the completed dataset (they
    > also open up and change other workbooks' data) . All of these macros
    > are in general plain modules, as you said Dave from: Insert|Module, and
    > they are all behind one worksheet.
    >
    > So should I use Application. Run and name the macros or is the Call
    > 'Macro' option better?. Thnx again!


    --

    Dave Peterson

  13. #13
    Ed
    Guest

    Re: Calling on a macro within a macro!

    A few thoughts:

    If I'm writing a routine that will use the same variables through several
    different Subs, I will usually put all the Subs in the same module so I can
    declare all the variables at the top. That way I don't accidentally re-Dim
    a variable name in another Sub and destroy it for the rest of the Subs.

    Remember that when you call a Sub from within another one, you have NOT left
    the first one! When the second Sub is finished, you will drop back into the
    first Sub just below the Call line. I got myself very tangled more than a
    few times by jumping from one to another, forgetting that at some point I
    had to return and finish everything out.

    If you're opening and closing a lot of files, you may want to monitor your
    objects in the Locals window, especially just before you think you're done,
    to make sure you haven't left some "ghost" of a file hanging in memory.
    This has got me a couple of times, too! If you want, put "Stop" on a single
    line just before your final End Sub - it will break the code and give you a
    chance to open the Locals window to check things.

    HTH
    Ed

    "mellowe" <[email protected]> wrote in message
    news:[email protected]...
    > Sorry just a quick question on this - does it matter where the other 5
    > macros are stored? Is it ok for them to be in different modules under
    > the same Excel sheet? thnx?
    >




  14. #14
    mellowe
    Guest

    Re: Calling on a macro within a macro!

    Thanks again everyone!!!
    Used the Call functionality and works perfect - using Application.run
    actually slowed down the macros!


Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1