+ Reply to Thread
Results 1 to 12 of 12

How to use a macro to run macro in other excel files?

  1. #1
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    How to use a macro to run macro in other excel files?

    Hi all,

    Hope all are well.

    I want a macro which will be placed in an excel file. When that macro is run, it should run a macro by name "Analyze" one after another in all 10 files (point 1) and once all done shall display a message "Analysis Completed".

    Please note below points.

    1. There are 10 different files with names as below.

    EMVS Alerts Log - Benelux.xlsm
    EMVS Alerts Log - CEE.xlsm
    EMVS Alerts Log - DACH.xlsm
    EMVS Alerts Log - GB+I.xlsm
    EMVS Alerts Log - Lower Case 1.xlsm
    EMVS Alerts Log - Lower Case 2.xlsm
    EMVS Alerts Log - Poland.xlsm
    EMVS Alerts Log - Scanda.xlsm
    EMVS Alerts Log - SouthernEuro.xlsm
    EMVS Alerts Log - Spain.xlsm

    2. The macro is to be run in above 10 files in sheets starting with name "All Data Summary - "
    For example, the sheets are named as All Data Summary - Poland in file EMVS Alerts Log - Poland.xlsm, All Data Summary - Scanda in file EMVS Alerts Log - Scanda.xlsm and so on.

    3. All 10 files in point 1 should be kept open before macro is run. If any file is not open, macro should give a message to open that file. I have an initial sample code for it as below which then continues with other requirement. Not sure if it can be used here.

    Please Login or Register  to view this content.
    4. The name of macro to be run in all 10 files is "Analyze"

    5. Post running of macro, all files shall still remain open.

    1 of the file in point 1 is attached for reference.

    Can someone help with the requirement please?
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,144

    Re: How to use a macro to run macro in other excel files?

    Try it like this:

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to use a macro to run macro in other excel files?

    Hi Bernie,

    Apologies for delayed response.

    The code works perfectly. Just 1 request - can you add a step in macro such that as and when Analyze macro is run in each file, the files should get saved

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,144

    Re: How to use a macro to run macro in other excel files?

    Sure:

    After this line

    Please Login or Register  to view this content.
    add these lines

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to use a macro to run macro in other excel files?

    Perfect. Thanks a bunch Bernie

  6. #6
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to use a macro to run macro in other excel files?

    Hi again Bernie,

    Thanks for the additional line in code to close the workbooks. Its really helpful, however, I want those workbooks to remain open which has "Miscellaneous" under column "AF" while rest closed. Is this possible

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,144

    Re: How to use a macro to run macro in other excel files?

    Add this to the top:

    Please Login or Register  to view this content.
    Then change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to use a macro to run macro in other excel files?

    Thanks for the response Bernie.

    I did as instructed but now none of the files close. All remain open

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,144

    Re: How to use a macro to run macro in other excel files?

    Sorry. Delete the "Set" in the "Set varM = ...." line.

    Note that the match needs to be exact...

  10. #10
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to use a macro to run macro in other excel files?

    Removed set, yet all files close.

    Please Login or Register  to view this content.
    Attaching 1 out of 10 files for reference.

    Is it because the sheet name "All Data Summary - Benelux" is not added in the close code. Because the target files will contain "Miscellaneous" in the aforementioned sheet under column AF.

    Note: 10 files have 10 different sheet names. However, all of the sheets start with "All Data Summary". So if sheet name is to be entered in code, then need to consider this point
    Attached Files Attached Files
    Last edited by rizwanulhasan; 11-22-2024 at 06:36 AM.

  11. #11
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,144

    Re: How to use a macro to run macro in other excel files?

    I have assumed that you have only one sheet name like "All Data Summary....."


    Add this to the top of the macro

    Please Login or Register  to view this content.
    And then change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    01-01-2022
    Location
    India
    MS-Off Ver
    Home 2021
    Posts
    896

    Re: How to use a macro to run macro in other excel files?

    Brilliant. Thanks a bunch Bernie

+ 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. PS files to PDF using excel macro
    By laxmanann in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2014, 01:46 AM
  2. [SOLVED] Save/Closed only macro related files and leave unrelated files open in excel?
    By rdowney79 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2013, 04:17 PM
  3. [SOLVED] Excel 2010 VB macro to open all files in folder and run a simple macro
    By MSFLNA in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2013, 02:54 PM
  4. Replies: 2
    Last Post: 11-26-2012, 08:33 AM
  5. macro should run with related files not with other excel files
    By bittu2010 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-16-2012, 05:25 PM
  6. Excel 2007 : Excel does not open files - only macro files
    By freeskier19 in forum Excel General
    Replies: 0
    Last Post: 02-02-2012, 07:42 PM
  7. Put a Macro into other Excel files
    By ducttape in forum Excel General
    Replies: 2
    Last Post: 01-18-2006, 02:14 PM

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