+ Reply to Thread
Results 1 to 4 of 4

Macro to open Excel file, run other macros save, and close file & repeat.

  1. #1
    Registered User
    Join Date
    03-26-2015
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    75

    Macro to open Excel file, run other macros save, and close file & repeat.

    Hi all,

    I've build an simulation in Excel and would like to collect results based on a number of different parameters. The file is designed to run a monte carlo simulation with one set of parameters. So I would need to make a copy of the simulation file and change the parameters in that copy. There is a macro in the file that runs the simulation X number of times and saves the results in different columns. Lets call the macro RunMonteCarlo.

    Is it possible to create a macro that opens the file (e.g. Simulation_1), runs 'RunMonteCarlo', saves the file and opens another file (e.g. Simulation_2) to run the 'RunMonteCarlo' macro in that file?

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,890

    Re: Macro to open Excel file, run other macros save, and close file & repeat.

    This link should show you some code that you can modify to include your other macros.

    http://www.thespreadsheetguru.com/th...a-given-folder
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    03-26-2015
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    75

    Re: Macro to open Excel file, run other macros save, and close file & repeat.

    Thanks for the loop macro. I've tried inserting my monte carlo macro (Run_MC) in the loop macro but I keep hitting errors.

    I've tried this line after the loop macro defines 'wb' as the opened workbook:

    wb.Run "Run_MC"

    It returns error 438: object doesnt support this poperty or method.

    I've also tried:

    Application.Run "Run_MC"

    But then I'm getting 1004: application defined error, probably because it wants to run Run_MC in the loop file instead of in the workbook it opened.

    Any suggestion on how to refer to Run_MC in the loop macro?

  4. #4
    Registered User
    Join Date
    03-26-2015
    Location
    Netherlands
    MS-Off Ver
    2013
    Posts
    75

    Re: Macro to open Excel file, run other macros save, and close file & repeat.

    Figured it out:

    Application.Run ("'" & myFile & "'!Run_MC")

+ 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. [SOLVED] VBA Open File/Run Macro/Close &Save/Open Next File
    By JPSIMMON in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-21-2015, 12:16 PM
  2. Problem With Open File and Save File With Saveas and then close the File
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-27-2013, 12:53 AM
  3. Replies: 0
    Last Post: 10-02-2013, 01:47 AM
  4. [SOLVED] VB to open a file, input on a file and close again, with NO macros/vb saved to file
    By unreal_event_horizon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-05-2012, 11:41 AM
  5. Macro to Open a file, transfer data, save and close
    By tforbes75 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-01-2011, 11:59 AM
  6. How to: Open file, format data, save file, close file and repeat.
    By thexeber in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-11-2010, 12:56 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