+ Reply to Thread
Results 1 to 15 of 15

Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

  1. #1
    Registered User
    Join Date
    06-13-2018
    Location
    Glasgow
    MS-Off Ver
    2013
    Posts
    33

    Angry Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    I am looking to automatically run multiple macros from multiple worksheets when the Excel file is opened. I have tried using

    Please Login or Register  to view this content.
    However, this only works if the user is on that specific worksheet when closing.

    I have 5 worksheets (Worksheet1, Worksheet 2, etc) and on each Worksheet there are corresponding macros (Macro 1, Macro 2, etc). The macros are for that specific sheet only and I need them to run automatically when the file is opened.

    Please help!
    Last edited by alansidman; 10-27-2018 at 07:28 AM. Reason: added code tags. Please do so in the future

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    No idea what the codes are, but you would probably have to select the correct sheet in each macro.

    Are they the same codes but for each sheet?

  3. #3
    Registered User
    Join Date
    06-13-2018
    Location
    Glasgow
    MS-Off Ver
    2013
    Posts
    33

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    No, the codes are all different for each sheet. I have also tried using [worksheet1.macro1] but that is not working either

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    When you have something that doesn't work, it always helps to describe what "doesn't work" means. Are you getting an error message? Does the code just not do anything? I don't see that here so I will guess.

    The macros in each worksheet must be declared as Public (not Private). If you have done this, then your code is simply
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Registered User
    Join Date
    06-13-2018
    Location
    Glasgow
    MS-Off Ver
    2013
    Posts
    33

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    When I changed it to your suggested code. I get the other message 'Run Time Error 424. Obeject Required' when opening.

    When I use
    Please Login or Register  to view this content.
    it does run the macro. However, it applies it to the last active sheet when it was originally closed. I need all macros to run but to the corresponding worksheet.

    Thanks.
    Last edited by AliGW; 10-27-2018 at 09:21 AM. Reason: Code tags added.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,430

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    When posting code snippets, please use the code tag button (#) provided on the toolbar. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Registered User
    Join Date
    06-13-2018
    Location
    Glasgow
    MS-Off Ver
    2013
    Posts
    33

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    I thought I did

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,430

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    No - I added the code tags for you - see the edit note at the foot of your post.

  9. #9
    Registered User
    Join Date
    06-13-2018
    Location
    Glasgow
    MS-Off Ver
    2013
    Posts
    33

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    Ah ok. Thank you
    Please Login or Register  to view this content.
    Can you help with my query?

  10. #10
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    Attaching a sample workbook enables others to work on your problem:

    To attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and click "manage attachments" to open the upload window.


    To add a file to a post

  11. #11
    Registered User
    Join Date
    06-13-2018
    Location
    Glasgow
    MS-Off Ver
    2013
    Posts
    33

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    Hi.

    I have attached a more basic copy but still getting the same issue. The Reset Macros only run on the last page visited. For example, if I close the doc while on Worksheet 3 the Macro will apply to that sheet only. I need the Macro to apply to the sheet the Reset button is.
    Attached Files Attached Files

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,430

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    Can you help with my query?
    No, sorry - I am afraid that I am not a VBA specialist.

  13. #13
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    The file you attached is very different than what you described in your first post.
    multiple macros from multiple worksheets
    There is no code in any of the worksheet modules. However, there is code in two general modules (Module1 and Module2) which you are calling from your Workbook_Open sub. These subs are assigned to the shapes in the first two sheets which act as buttons. This code runs perfectly when I open the file, executing both subs that are called. It doesn't matter what sheet is active when I close the file; both subs always run. So the file you attached does not replicate the problem that you described in your first post.

  14. #14
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,475

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    There were problems with selects in your macros.

    You can use these, they no longer have selects.

    Please Login or Register  to view this content.
    Workbook Module
    Please Login or Register  to view this content.
    You can also just combine the codes
    Please Login or Register  to view this content.
    Worksheet Module
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    06-13-2018
    Location
    Glasgow
    MS-Off Ver
    2013
    Posts
    33

    Re: Running Multiple Macros From Multiple Worksheets Automatically When File Is Opened

    Thanks Davesexcel, you are a legend. The 'With' and onecode combo worked a treat!

    Thanks again!

+ 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. Running multiple macros on different worksheets on close
    By jcopier in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-25-2015, 11:09 AM
  2. [SOLVED] Running 3 different macros across selected multiple worksheets in one workbook
    By almugs in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-12-2013, 08:40 AM
  3. [SOLVED] Macros not running unless Workbooks are opened with File>Open
    By Benjooster in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2013, 11:02 AM
  4. How to set a Global Macros so that it gets opened every time an excel file is opened?
    By pericopericone in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2013, 05:53 AM
  5. Running Macros on multiple worksheets
    By shivrklfc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2012, 11:11 AM
  6. Macros not working when a workbook is opened by multiple users
    By CJD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2009, 04:00 PM
  7. Markup Multiple Values in Multiple Sheets When File is Opened
    By Oneiros_alpha in forum Excel General
    Replies: 1
    Last Post: 04-15-2009, 01:48 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