+ Reply to Thread
Results 1 to 5 of 5

Triggering an event based on actions in another Workbook

  1. #1
    Registered User
    Join Date
    08-05-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Triggering an event based on actions in another Workbook

    Hi,

    I'm developing a counter/timer spreadsheet.

    Initially the spreadsheet uses an rtd which pulls information from elsewhere to detect if the counter on/off conditions are met in combination with an application.ontime sub, however the refresh rate is too slow. The triggering event can be less than a second, so the code I've written can't detect the triggering action and sometimes, the rtd doesn't refresh in time to detect.

    One possible way to detect this trigger is based on an Active X button on another spreadsheet. Pressing once starts/stops an action.

    I can't modify the triggering spreadsheet as it's a secured controlled document, so if I could write a script on another excel spreadsheet to detect either the triggering of sub/clicking of the button that would be great.

    How would I start off on this?

    Thanks!

    Joel.

  2. #2
    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: Triggering an event based on actions in another Workbook

    Hi Joel,

    Can you provide more detail as to what the trigger actually is? Absent that information all I might suggest is:
    - use Windows timers rather than OnTime
    - use Withevents variables for either the button or workbook, depending on what event you actually need to catch.
    - Use Setlinkondata to run your code based on the RTD calculating.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    08-05-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Re: Triggering an event based on actions in another Workbook

    Hi,

    Thanks for the reply.

    The spreadsheet has fair bit more complication to it but the crux of My code is as:

    Sub Check()

    With Workbooks("Timer").Worksheets(1)

    ' If it detects that the second counter has passed the 1 min mark then it backs the Time In counter up to the time it went out
    If .Range("Test2") = "OUT" And DateDiff("s", .Range("OutTime"), Time()) >= 59 Then
    .Range("OutCheck") = True 'If set to true, it means that the counter logs as out.
    .Range("SecondCheck") = False
    End If

    If .Range("Test") = "OUT" And .Range("Test2") = "IN" Then
    .Range("SecondCheck") = True 'Gets the second counter to start Running
    .Range("OutTime") = Time() ' logs the time it went out for comparison later if relevant
    .Range("Test2") = .Range("Test") ' logs the current status as out
    GoTo Whoop
    End If

    If .Range("Test") = "IN" And .Range("Test2") = "OUT" Then
    .Range("SecondCheck") = False 'Stops the second out counter
    .Range("Test2") = Range("Test")
    If .Range("OutCheck") = True Then
    .Range("DurationOut") = .Range("TotalOutTime") 'Adds the time out to the total time out counter
    .Range("OutCheck") = False ' changes status to in
    End If
    End If

    Whoop:
    TTime = DateAdd("s", 1, Now())
    Application.OnTime TTime, "Check"
    .Range("Running") = "Timer Running"

    End With

    End Sub

    So as mentioned I'm trying to log when a status change occurs. I have a cell is in the spreadsheet that gets a time based on the NOW() function. Application .ontime is only for checking when the status change occurs.

    Range("Test") is triggered by an RTD. This RTD's update frequency unfortunately may not be fast enough and this I cannot change. However information fed into the RTD which causes the change is actually from another spreadsheet and based on a couple of ActiveX buttons. This being the "source" trigger, would make it the only way to detect the status change. But the "source" cannot be touched hence I need a way of tracking the trigger from outside the source workbook.

    Thanks!

  4. #4
    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: Triggering an event based on actions in another Workbook

    From what you say, it may be easier to use the SetLinkOnData method, but here is an example of how to hook into the command buttons.
    1. Add a new class module to your workbook and add the following code to it
      Please Login or Register  to view this content.
    2. In a new module in your workbook, you need code like this
      Please Login or Register  to view this content.
    3. You will need to adjust the names of the class, workbook, worksheet and commandbutton to match your circumstance.


    After running checkit once, clicking the button in the other workbook should pop up a message box.

  5. #5
    Registered User
    Join Date
    08-05-2016
    Location
    Singapore
    MS-Off Ver
    2013
    Posts
    9

    Re: Triggering an event based on actions in another Workbook

    Thanks! Works like a charm, Never thought of using a class module.

    FYI anyone else who wants to use this needs to be aware to add the Forms 2.0 reference, was a bit stumped when it wasn't working.

+ 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] Prevent BeforeClose Event from triggering if workbook closes with shutdown timer
    By Jerbinator in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-09-2015, 10:18 AM
  2. Need Help with Event Triggering when value changes
    By calvinloo in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-12-2015, 03:54 AM
  3. EVENT triggering?
    By EXLent in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 08-19-2014, 07:16 AM
  4. Event triggering
    By Sarimdesert in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2014, 03:26 AM
  5. VBA Event triggering
    By teachMeExcel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2012, 02:12 PM
  6. ComboBox_Change Event Not Triggering
    By yay_excel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2011, 02:22 PM
  7. [SOLVED] Workbook Open Event not triggering
    By Mike Jerakis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2006, 05:15 PM

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