+ Reply to Thread
Results 1 to 6 of 6

Running macros in other workbooks

  1. #1
    Forum Contributor
    Join Date
    04-06-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    103

    Running macros in other workbooks

    Hi

    I have some code in a workbook called Order.xls
    This code opens a list of specified workbooks. It opens the first workbook runs a macro within that workbook then closes.

    I would then like to come back to the Order.xls workbook and open the next specified workbook, run the macro within that workbook and close. And continue to do this until all specified workbooks in the Order.xls workbook code have been opened.

    The trouble I am having is that after the 1st workbook has been opened and the macro within the workbook has ran, the macro simply stops as it doesnt know to come back to the Order.xls workbook and continue with the code.

    The code I am using is as follows:


    Please Login or Register  to view this content.


    This is the code which sits in each workbook

    Please Login or Register  to view this content.

    After this runs, I would like to go back to the Refresh code and continue to open Test2.xls


    Any ideas or better ways I can accomplish this?
    Thanks

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Running macros in other workbooks

    Do all the workbooks share the same name plus a number?

    It would be easier to have the code in the main workbook & refer to the opened workbook
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    04-06-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    103

    Re: Running macros in other workbooks

    Hi, thanks for the reply

    The workbooks are named differently - I used test/test2 as an example
    I tried to do as you suggested and put both macros into the Order.xls workbook - when I did this, the test.xls workbook would open/close and move onto the next workbook however the pivot tables did not refresh.

    Any ideas?
    Thanks

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    No macros in other workbooks necessary

    You won't need macros in opened workbooks.

    Please Login or Register  to view this content.



  5. #5
    Forum Contributor
    Join Date
    04-06-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    103

    Re: Running macros in other workbooks

    Hi, thanks for the reply
    That's working great however, when I reopen the Test and Test2 the windows are hidden.. I have to go to Window > Unhide Test1... then the same for Test2... do you know why this might be?

    Thanks again

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Running macros in other workbooks

    It's meant to speed up your code.

    If you want it otherwise use:
    Please Login or Register  to view this content.

+ 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