+ Reply to Thread
Results 1 to 6 of 6

Workbook Events triggered from another active workbook

  1. #1
    Registered User
    Join Date
    03-12-2017
    Location
    Wales, UK
    MS-Off Ver
    2016
    Posts
    11

    Workbook Events triggered from another active workbook

    OK, sorry about the title; but here is the issue:
    I have a workbook that has a timeout function that will firstly warn a user about an inactive workbook and then if no response is given save and close it. Upon testing this though I have found that if another workbook is open in excel and is being used, the timer continually resets and the inactive workbook that is still open won't close.
    I have the timer reset subs called from the workbook_open, workbook_sheetchange, workbook_selectionchange and workbook_calculate events.
    Any ideas of how to get around this happening?
    I had thought that maybe a test to check if the sheet triggering the change is within the inactive workbook or not, but my VBA knowledge doesn't stretch that far!
    Any suggestions would be greatly appreciated.
    Dave

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Workbook Events triggered from another active workbook

    This may be because both workbooks are open in the same instance of Excel. This is normally a good thing: shared resources are more efficient. But I found that in some cases, you may be working on a small workbook and cause it to recalculate and when it does, it also recalculates every other workbook open in that same instance of Excel. Or you may have a workbook that is churning away keeping you from updating another workbook.

    You can open another workbook by calling Excel in a shortcut, using the -x option. I've put this shortcut into my send to menu so I can right click and send an excel file to a separate instance.

    I don't know if this will fix your issue but it's worth a try.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    03-12-2017
    Location
    Wales, UK
    MS-Off Ver
    2016
    Posts
    11

    Re: Workbook Events triggered from another active workbook

    Quote Originally Posted by dflak View Post
    This may be because both workbooks are open in the same instance of Excel. This is normally a good thing: shared resources are more efficient. But I found that in some cases, you may be working on a small workbook and cause it to recalculate and when it does, it also recalculates every other workbook open in that same instance of Excel. Or you may have a workbook that is churning away keeping you from updating another workbook.

    You can open another workbook by calling Excel in a shortcut, using the -x option. I've put this shortcut into my send to menu so I can right click and send an excel file to a separate instance.

    I don't know if this will fix your issue but it's worth a try.
    Thanks for the idea, I'll give that a go. If that is the issue it won't be a solution for me though, as the timer is designed to run in the background without the end user necessarily being aware of it, and so will very possibly be using the same instance of excel for another workbook. Would putting the timer reset code into each individual sheet's code be a solution do you think?

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Workbook Events triggered from another active workbook

    I think what may be resetting the timer is the workbook calculate event. When multiple workbooks are open in the same instance of Excel, a calculation in one workbook triggers a calculation in all workbooks. So perhaps there is a way to caveat the workbook_calculate event so this doesn't happen. I'm not sure how to do that. Perhaps replace it with worksheet_change events. This way you limit the effect to only worksheets in the workbook with the timer. Calculations triggered by other workbooks shouldn't affect the timer workbook unless there is a =NOW() formula somewhere.

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Workbook Events triggered from another active workbook

    One might test if the active workbook is the one containing the code?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    Registered User
    Join Date
    03-12-2017
    Location
    Wales, UK
    MS-Off Ver
    2016
    Posts
    11
    Quote Originally Posted by dflak View Post
    I think what may be resetting the timer is the workbook calculate event. When multiple workbooks are open in the same instance of Excel, a calculation in one workbook triggers a calculation in all workbooks. So perhaps there is a way to caveat the workbook_calculate event so this doesn't happen. I'm not sure how to do that. Perhaps replace it with worksheet_change events. This way you limit the effect to only worksheets in the workbook with the timer. Calculations triggered by other workbooks shouldn't affect the timer workbook unless there is a =NOW() formula somewhere.
    Thanks dflak, this sorted it. I simply removed the workbook_calculate event. The time now only resets when changes are made within the workbook running the code. As it was only a test to check if the workbook was being used, the calculate event wasn't really needed anyway. I just have it associated to the _change and _selectionchange events now and it works a treat.

+ 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] Saving as a PDF on the active workbook Path and name same as active workbook name
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-22-2016, 12:25 PM
  2. Open Another Workbook from Active Workbook but stay on Active Workbook.
    By Tona in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-29-2014, 06:33 AM
  3. [SOLVED] Code to detect previous active workbook instead of current active workbook
    By kosherboy in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-25-2014, 01:58 AM
  4. VBA macro for hyperlink to active workbook in the active workbook path
    By Scott Taylor in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-10-2013, 05:37 AM
  5. is it possible to have 2 events active in same workbook?
    By fabrecass in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-26-2013, 05:24 AM
  6. add-in procedures called from active workbook events
    By doco in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2006, 03:20 AM
  7. Help on Workbook close and workbook save events
    By Adam Harding in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2005, 12:05 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