+ Reply to Thread
Results 1 to 4 of 4

Macro to open a file, input value into a cell, and run a macro from file

  1. #1
    Registered User
    Join Date
    06-22-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    9

    Macro to open a file, input value into a cell, and run a macro from file

    I have a worksheet with a list of Order Numbers in Column A, starting from cell A1. I want to create a macro that will loop through all the Order Numbers in Column A and for each Order Number do the following:

    1. Open a file (GenerateReport.xls) in a folder path (C:\temp\)
    2. Input the Order Number into cell C6 of the Data tab in GenerateReport.xls
    3. Run a macro (Gen_Report) in GenerateReport.xls (this macro will create a report based on the Order Number in cell C6 and close the GenerateReport.xls file)
    4. Repeat steps 1,2,3 for the next Order Number

    Would really appreciate any help that I can get as I am newbie to VBA. Thank you!
    Last edited by wkhor; 08-11-2011 at 03:03 AM.

  2. #2
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Macro to open a file, input value into a cell, and run a macro from file

    Hi wkhor...Does the macro Gen_Report already exist? If so try this:
    Please Login or Register  to view this content.
    -Greg If this is helpful, pls click Star icon in lower left corner

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Macro to open a file, input value into a cell, and run a macro from file

    Hi wkhor,

    Try this - just change the three variables I've commented with 'Change to suit' if necessary:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Registered User
    Join Date
    06-22-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro to open a file, input value into a cell, and run a macro from file

    Thanks for the quick response Robert. The macro Gen_Report already exists.

    Your code works great! The only thing i changed was adding the
    Workbooks.Open Filename:=strFileName
    into the For-Next loop because the Gen_Report macro closes the GenerateReport.xls file everytime the macro is run.

+ Reply to 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