Creating a stop button with vba

  • So i found the code below online. I mingled with it a little bit but when I clicked the stop button twice I had to debug it. I figured I can do an if statement that said if this is running do this, however, I don't remember how to do it. I tried something like

    Code
    1. Sub stopAuto()
    2. If Application.OnTime(nexttime, "AutoRefresh") Then
    3. Application.OnTime nexttime, "AutoRefresh", , False
    4. Else
    5. Exit Sub
    6. End If
    7. End Sub

    but that gave me compiler errors I am confusing this with something else. I am just trying to figure out is there a way to say if start button is active stop it or else exit sub

  • Basically I am making my excel spreadsheet refresh because I have some stock market quotes on it. I can press the start button to start a timer numerous times and it does not have an error. My stop button however, seems to have a problem if I pressed it more than once. I try to write some code that says if pressed don't allow it to be pressed but I forgot how. I have been working more in the formulas not so much vba section of excel :) thank you

  • I figured it out what I did was this below on code. the new addition is highlighted in red :)


    Code
    1. Sub stopAuto()
    2. On Error GoTo er
    3. Application.OnTime nexttime, "AutoRefresh", , False
    4. er:
    5. Exit Sub
    6. End Sub