+ Reply to Thread
Results 1 to 6 of 6

Macro to run another macro

  1. #1
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Macro to run another macro

    I am running a macro that opens another file, runs a macro in that workbook and after it runs my macro extracts data from it. The problem I am having is that if an error occurs while the macro that is running in the workbook I open (due to the parameters selected), that macro will have a message box pop up that says "No Rates Found". My macro is still running because it doesn't know that the other has stopped and wont produce the data.

    What is a way to have my macro stop when this happens and have a message box pop up also. I don't have access to the macro I am running against. I just pulled the name of the macro behind the button when you right click and select assign macro like you can see below.


    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Macro to run another macro

    Quote Originally Posted by mattress58 View Post
    ... What is a way to have my macro stop when this happens and have a message box pop up also. I don't have access to the macro I am running against. I just pulled the name of the macro behind the button when you right click and select assign macro like you can see below.


    Please Login or Register  to view this content.
    The best way to resolve this is for you to post the complete macros you are running. Otherwise, unless someone has ESP, there is no way to help you.
    Use Alt + F11 to open the VB Editor. Then paste the macros to this thread.
    If I helped in any way, please click the star

  3. #3
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Re: Macro to run another macro

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro to run another macro

    Hi mattress58,

    You need to recode the son Macro as a function. It can then return a value to the father macro. See the attached workbooks and the sample code that follows:

    Father Workbook in an ordinary code module (e.g. Module1):
    Please Login or Register  to view this content.
    Son Workbook in an ordinary code module (e.g. Module1):
    Please Login or Register  to view this content.
    ------------------------

    Typical flow of control in the son macro is as follows (non-working pseudocode):
    Please Login or Register  to view this content.
    Lewis

  5. #5
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Re: Macro to run another macro

    I am trying to add this in my workbook. The question I have is : Is this looking for an error after the macro opens the other workbook or if there is an error opening the other workbook?

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Macro to run another macro

    If there is an error opening the other workbook, the Father Workbook (macro) will generate a runtime error.
    For example, RunTime Error 1004 will occur if the file containing the Son Macro is NOT OPEN, when you try to call the Son Macro using Application.Run. This type of error is in the Father Workbook ONLY.

    Once you are successful, calling the Son Macro, the Son Macro does whatever processing you tell it to do in the code. It is your responsibility to identify errors when the Son Macro runs. These errors can be Excel RunTime errors (e.g. Range("A33E") - illegal cell Address ), or data errors that you define such as a cell that should contain a number has text in it, or a cell that should contain data is empty.

    For each of these errors in the Son Macro, you assign an arbitrary number. You return the error to the Father Macro, and the father macro displays the appropriate message.

    I hope I understood your question. If not please ask for more help.

    Lewis

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using a macro on workbook1 to create a button in wb2 and assigning macro "wb2!macro"
    By penfold1992 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2014, 11:39 AM
  2. [SOLVED] Macro to show Which macro didnt work in a nested macro
    By akhileshgs in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-10-2013, 03:21 AM
  3. Perform macro "on open" specific file- store macro in Personal Macro Workbook?
    By thompssc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2012, 12:38 PM
  4. lookup macro, solver macro, realtime macro
    By xelhelp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-02-2011, 06:14 PM
  5. Cannot find macro error when running a macro from a macro in a diffrent workbook.
    By Acrobatic82 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2010, 09:22 AM

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