+ Reply to Thread
Results 1 to 10 of 10

Macro Re-opens Workbook After Closing

  1. #1
    Registered User
    Join Date
    04-19-2011
    Location
    Leeds
    MS-Off Ver
    Excel 365
    Posts
    48

    Macro Re-opens Workbook After Closing

    Hi All,

    I have a workbook that I have put a Workbook_Open macro in:-

    Sub Workbook_Open()
    Timer
    End Sub


    This runs a timer:-

    Sub Timer()
    Application.OnTime Now + TimeValue("00:05:00"), "RefreshAllTables"
    End Sub


    Which refreshes my data, below:-

    Sub RefreshAllTables()

    ActiveWorkbook.RefreshAll
    Timer

    End Sub


    Firstly, I'm sure these can all be put together in one macro (I'm a complete novice at this) but, interestingly, when I close the workbook, the macro still appears to be running and, when it refreshes the data, it re-opens the workbook.

    Can I put an Auto_Close in that will stop the macro running but will not affect anything that may be running at the same time.

    As always, any help is much appreciated.

    Feastie.
    There's always a way.

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Macro Re-opens Workbook After Closing

    It looks as if you are running the Timer Sub twice - Once when the workbook opens and again in the "RefreshAllTables" Sub. Was this intentional?
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    04-19-2011
    Location
    Leeds
    MS-Off Ver
    Excel 365
    Posts
    48

    Re: Macro Re-opens Workbook After Closing

    I was trying to get it back to the Timer macro, I guess you're saying it doesn't stop counting just because it has focussed on the update?
    Would that cause the issue with the re-open?

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Re-opens Workbook After Closing

    Hi Feastie

    Please wrap your Code in Code Tags.

    When you close the Workbook you need to stop the Timer.

    In the ThisWorkbook Module...
    Please Login or Register  to view this content.
    In a General Module...
    Please Login or Register  to view this content.
    Last edited by jaslake; 09-14-2015 at 12:16 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Registered User
    Join Date
    04-19-2011
    Location
    Leeds
    MS-Off Ver
    Excel 365
    Posts
    48

    Re: Macro Re-opens Workbook After Closing

    Thanks Jaslake,

    apologies for the format, I've never posted code before.
    Should I be adding these to what I already have or am I replacing some of it?

    Thanks, Feastie.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Re-opens Workbook After Closing

    Hi Feastie

    You will NOT be replacing anything.

    If you HAVE a WorkBook Before Close Event ADD this Line of Code
    Please Login or Register  to view this content.
    Otherwise past the ENTIRE Code into ThisWorkbook Module.
    Please Login or Register  to view this content.
    This Code is NEW and does not REPLACE anything. Paste the ENTIRE Code in a General Module.
    Please Login or Register  to view this content.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Re-opens Workbook After Closing

    Hi Feastie

    I've been informed that the Stop Timer Code needs to be modified...let me get back to you.

    Sorry for the inconvenience.

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Re-opens Workbook After Closing

    Hi Feastie

    In Workbook.Open Code, replace this

    Please Login or Register  to view this content.
    with this (my personal preference)
    Please Login or Register  to view this content.
    Also, place this in the Workbook Module.
    Please Login or Register  to view this content.
    In a General Module:

    Replace this
    Please Login or Register  to view this content.
    with this
    Please Login or Register  to view this content.
    Add this
    Please Login or Register  to view this content.
    Also, in that General Module, place this line if Code at the very Top of the Module.
    Please Login or Register  to view this content.
    In your "RefreshAllTables" Code replace this Line
    Please Login or Register  to view this content.
    with this
    Please Login or Register  to view this content.
    A tested sample File is attached for your review.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-19-2011
    Location
    Leeds
    MS-Off Ver
    Excel 365
    Posts
    48

    Re: Macro Re-opens Workbook After Closing

    Thanks Jaslake,

    it works perfectly, reputation added to.

    Feastie.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro Re-opens Workbook After Closing

    You're welcome...glad I could help. Thanks for the Rep.

    And a Thanks to shg...

+ 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] Need a macro that opens another workbook but stays in current workbook
    By shoes1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-28-2015, 08:44 PM
  2. how can i execute a macro in current workbook after another workbook opens?
    By sds1126 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2014, 09:36 AM
  3. Replies: 3
    Last Post: 07-12-2014, 06:04 AM
  4. Replies: 1
    Last Post: 03-10-2014, 05:20 AM
  5. [SOLVED] Help me please !!!!! file closing as soon as it opens due to wrong coading
    By sabhay in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2012, 02:10 PM
  6. [SOLVED] Code closing workbook as soon it opens
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-13-2012, 02:35 PM
  7. Workbook automatically opens after closing
    By SJB in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-08-2010, 09:12 PM

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