Results 1 to 2 of 2

Thread: How To Stop An OnTime Scheduled Macro Without Getting An Error

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0

    Question How To Stop An OnTime Scheduled Macro Without Getting An Error

    I have posted this on other forum but with no result, hope anyone here can assist me with the code, thank you

    Getting Live MT4 forex data

    any possible way that i can run the vba and still able to do other task on other workbook?

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Yes, it can be done. I've added a button to make it easier for you to stop the macro in between. Code used

    In Module1
    Code:
    Option Explicit
    Public blnStopUpdate As Boolean
    Dim dtmAlertTime As Date
    
    
    Private Sub EventMacro()
    
    
        Dim lngLoop As Integer
        
        For lngLoop = 2 To 2500
            If Range("Q" & lngLoop) = Range("$L$2") Then
                Range("S" & lngLoop).Value = Range("N2").Value
            End If
        Next lngLoop
        DoEvents
        If Not blnStopUpdate Then
            dtmAlertTime = Now + TimeValue("00:00:05")
            Application.OnTime dtmAlertTime, "EventMacro"
        End If
    
    
    End Sub
    
    
    Sub GetLiveData()
    
    
        dtmAlertTime = Now + TimeValue("00:00:05")         'Set time (sec) for updating data
        Application.OnTime dtmAlertTime, "EventMacro"
    
    
    End Sub
    
    
    Private Sub SetTimeNow()
    
    
        Dim lngLoop As Integer
    
    
        Application.ScreenUpdating = False
        Range("R2").Value = Evaluate("=INT(NOW()/(1/288))*(1/288)+288*(1/288)*(1/288)")
        For lngLoop = 1 + 2 To 2500 + 2
            Range("R" & lngLoop).Value = Range("R" & lngLoop - 1).Value + Range("U2").Value
        Next lngLoop
        Columns("S:S").ClearContents
        Range("F2").Select
        Application.ScreenUpdating = True
        
    End Sub
    In sheet1
    Code:
    Private Sub CommandButton1_Click()
    
        Application.Run "'get Live Data_Test.xls'!GetLiveData"
    
    
    End Sub
    
    
    Private Sub CommandButton2_Click()
    
    
        Application.Run "'get Live Data_Test.xls'!SetTimeNow"
    
    
    End Sub
    
    
    
    
    Private Sub CommandButton3_Click()
    
    
        blnStopUpdate = True
        
    End Sub
    By the way, the attachment is only meant for MT4 (Meta Trader) users.
    Attached Files Attached Files
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

Similar Threads

  1. How To Stop Duplicate Incomig Emails In Outlook
    By Howardc in forum Outlook Help
    Replies: 4
    Last Post: 11-15-2013, 08:00 AM
  2. Replies: 9
    Last Post: 08-05-2013, 11:28 PM
  3. Replies: 22
    Last Post: 03-19-2013, 07:57 AM
  4. Scheduled emailing with VB + Outlook
    By BARIS in forum Excel Help
    Replies: 0
    Last Post: 01-16-2013, 02:22 AM
  5. Replies: 2
    Last Post: 12-04-2012, 02:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •