+ Reply to Thread
Results 1 to 9 of 9

Run Macro to all open workbooks.

  1. #1
    Registered User
    Join Date
    03-09-2019
    Location
    Manila
    MS-Off Ver
    2010
    Posts
    9

    Question Run Macro to all open workbooks.

    Hello!, I am new to excel and macro recording is a big help for me.
    I have 100 excel workbooks i one folder(This can't be consolidated due to management reasons), my problem is every time we are making changes in in templates or formulas,what i am currently doing is I will record a macro and run each in every 100 workbooks, is there any way that i can run / click to activate macro in all open workbooks? by the way all my workbooks have same template.
    Macro recording and run it to each workbooks is very helpful to me, but i'm worried that soon my 100 workbooks will doubled.

  2. #2
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Run Macro to all open workbooks.

    You could do it with something on the lines of

    Please Login or Register  to view this content.
    Note that you would need to qualify any object / sheet references in your existing code with a wb. prefix.

  3. #3
    Registered User
    Join Date
    03-09-2019
    Location
    Manila
    MS-Off Ver
    2010
    Posts
    9

    Re: Run Macro to all open workbooks.

    Thank you so much, i created a new workbook and a button to run this code i just tried to add date in all open workbooks, and last question, does the recorded macro code will work here too? i didn't try coz i don't wanna ruin my template

    Sorry for my grammar hope u understand.

  4. #4
    Registered User
    Join Date
    03-09-2019
    Location
    Manila
    MS-Off Ver
    2010
    Posts
    9

    Re: Run Macro to all open workbooks.

    Hello again, i'm sorry i'm not familiar with VBA. i tried this code to hide some columns but it doesn't work.
    Please Login or Register  to view this content.
    the code comes from recorded macro, i just added wb.worksheets(1) to call the first sheet in open workbook, where did i go wrong?
    Last edited by Fcxx; 03-24-2019 at 10:14 PM.

  5. #5
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Run Macro to all open workbooks.

    It should either be wb.Worksheets or wb.Sheets, both in the same line will cause an error. Selection, ActiveCell or ActiveSheet should not have anything in front.
    Please Login or Register  to view this content.
    In addition to that, the macro recorder does not produce very efficient code, selection and activation are almost never needed, everything in red above can be deleted and the code will still function.
    Please Login or Register  to view this content.
    Enhancing that further still, if you have a lot of lines that will refer to wb.WorkSheets(1) then you can use a 'With' block to cut down on the typing / copy & paste needed to write the code.
    Note that the lines between With and End With all start with a dot / period, this links them to wb.WorkSheets(1) that the section is working 'With', if there is no dot / period at the start of the line then that line might not be linked to the correct sheet.
    Please Login or Register  to view this content.
    One final point. If you have multiple instances of Excel open, then this will not span all of them. Only the workbooks in the instance that holds the code.

  6. #6
    Registered User
    Join Date
    03-09-2019
    Location
    Manila
    MS-Off Ver
    2010
    Posts
    9

    Re: Run Macro to all open workbooks.

    Wow! This code did exactly what i wanted to, Thank you so much for your help.

  7. #7
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Run Macro to all open workbooks.

    You're welcome! Thanks for the feedback and rep!

    Just a quick check, do you understand the bit about multiple instances of excel?

    On older versions, opening workbooks from windows folders would cause each to open in a new instance, opening them from the file menu would open them all in the same instance.
    This was changed at some point, so I'm not sure if that is how your version would work or not.

  8. #8
    Registered User
    Join Date
    03-09-2019
    Location
    Manila
    MS-Off Ver
    2010
    Posts
    9

    Re: Run Macro to all open workbooks.

    Actually all i know in excel as of now is the mostly use formulas and formats, and i was introduce in VBA a week ago since i need some codes to lessen my working hours, i have a guess what multiple instances is, and in some cases i experience that when 1 excel file is generating and unable to use the other files are affected, is this what multiple instances means? I am using Excel 2016 by the way.

  9. #9
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Run Macro to all open workbooks.

    As you're using 2016, you should be safe. Microsoft made opening a second instance of excel so complicated that it's almost impossible to do it even when you want to.

    If you are unable to do anything with other excel files while one is working then they are all in the same instance.

    If you are able to make changes to one while another is working then they are in separate instances.

    As long as you only open excel once, either from the windows desktop / start menu, or by double clicking a workbook icon in a folder you can guarantee that all will be in the same instance regardless of which version you are using.
    Once you have done this, open the rest of your workbooks from within excel by going to the File tab on the ribbon, then Open.

+ 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. Replies: 1
    Last Post: 03-31-2016, 02:06 AM
  2. [SOLVED] Macro to open multiple workbooks and initiate each Macro
    By JPSIMMON in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2015, 09:16 PM
  3. Macro on two open workbooks?
    By Hambone70 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2013, 01:53 PM
  4. Macro to Open Up Workbooks
    By hyattj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2013, 12:35 PM
  5. macro to open multiple workbooks at once
    By easty in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-30-2010, 08:48 PM
  6. open two workbooks from one macro
    By excellentexcel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-06-2009, 03:08 AM
  7. Macro to open and close other workbooks
    By nms2130 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2008, 10:28 AM

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