+ Reply to Thread
Results 1 to 6 of 6

Same VBA code executed sequentially to each workbook and worksheet

  1. #1
    Registered User
    Join Date
    09-02-2011
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    91

    Question Same VBA code executed sequentially to each workbook and worksheet

    Hi all

    tried to find answer in the forum but it seems there is no topic for this.

    i have 10 workbooks with different names - each of them contains 1 worksheet with the same name as the workbook. (e.g. report1.xlsx - name of the worksheet - report)
    i have a code that transforms the data and copy it to another workbook - at the end the data is collected and transformed into one workbook and worksheet
    currently i made the code simple and copied the same code for each workbook and worksheet (all my workbooks are open while i execute code - im trying also to make it open them)

    my question is
    is there a way to set the workbook name and worksheet name as a variable and to be executed like -

    set next workbook name
    set next worksheet name

    execute code

    goback to set next names


    after the last workbook quit
    Last edited by godlev; 03-26-2018 at 09:52 AM. Reason: spell check
    Truth fears no questions.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Same VBA code executed sequentially to each workbook and worksheet

    You could easily loop through all the open workbooks, excluding the workbook you are copying to.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-02-2011
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    91

    Re: Same VBA code executed sequentially to each workbook and worksheet

    i have tried similar set up of the code but in the begining of the code array with the workbook names and cant seem to be able to connect it with the FOR part

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Same VBA code executed sequentially to each workbook and worksheet

    Are the workbooks open or not?

    In your original post you seemed to indicate all the workbooks you want to get data from are open.

  5. #5
    Registered User
    Join Date
    09-02-2011
    Location
    Bulgaria
    MS-Off Ver
    2013
    Posts
    91

    Re: Same VBA code executed sequentially to each workbook and worksheet

    Quote Originally Posted by Norie View Post
    Are the workbooks open or not?

    In your original post you seemed to indicate all the workbooks you want to get data from are open.
    yes they are open but i want to avoid copying other data if there are other workbooks open

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Same VBA code executed sequentially to each workbook and worksheet

    Do you have a list of the workbook names you do want to get data from?

+ 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] Daily executed code
    By Joakim N in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-06-2013, 11:18 AM
  2. EXCEL: Last Executed Line In VBA Code
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2013, 09:54 AM
  3. [SOLVED] Command Button in one workbook and data to be executed in another workbook
    By aswin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2012, 06:02 AM
  4. Replies: 1
    Last Post: 06-02-2010, 05:18 AM
  5. Outlook code executed from excel VBA
    By marcospaterson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-29-2009, 06:58 PM
  6. Code runs when stepped, not when executed...
    By Stu M in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-24-2009, 07:21 AM
  7. Code never gets executed in for loop
    By msa969 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2009, 04:09 PM
  8. part of a code not being executed
    By Valeria in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-28-2005, 03:05 AM

Tags for this Thread

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