How make a timer/stopwatch "start" button change color and blink when first clicked?

  • Hi,


    Let me start my question by saying that I am new to VBA. I am using the following (link below) timer/stopwatch excel worksheet which helps me with my job.


    https://chandoo.org/wp/building-a-si...ed-case-study/


    I would like to change one thing with the timer/stopwatch in that the button you click to start the timer/stopwatch stays blue when first clicked and the only thing that is different is the text changes from start to stop. I would like for the button when first clicked for the text to not only change to stop but for the button color to change to red and also for the button to blink/flash. I know that a button that blinks/flashes is very annoying but I “NEED” the stop button to be annoying so that I don’t forget to click stop after the task is completed that I am timing. I will be the only one using the spreadsheet so there is no chance it will annoy someone else as I know blinking/flashing is a no-no.


    From the research I have done I “think” I would need to delete the current button as it is a “shape” and insert an “activex” button. Unfortunately, I don’t what the next step would be as I can’t find the code to make the button change to red and flash/blink and even if I could find the code I am not exactly sure how to enter the code and link it to the new button. Any help would be greatly appreciated.


    Thank you in advance for any help to get me pointed in the right direction,


    yeto


    Code
    Sub startStopTimer()
        If Range("timer.button.label") = "Start" Then
            Range("time.stamp.start").Offset(Range("count.of.timestamps") + 1).Value = Now
            Range("timer.button.label") = "Stop"
        Else
            Range("time.stamp.start").Offset(Range("count.of.timestamps"), 1).Value = Now - Range("time.stamp.start").Offset(Range("count.of.timestamps"))
            Range("timer.button.label") = "Start"
        End If
    End Sub
  • You are right ... Change to the ActiveX button. It has a property of BGColor ... or some such name. That will change the color. If you want it to blink... I'd have a seperate routine that you use to flicker the timer.

  • Here's a possible solution. This code is behind the ActiveX button



    This code is on a regular module sheet

  • Here's a possible solution. This code is behind the ActiveX button



    This code is on a regular module sheet


    Thank you for taking time out of your day to reply. I will definitely try the above codes to the best of my ability and report back.


    Kind regards,
    yeto

  • :thumbcoo:


    Good Luck!

  • :thumbcoo:


    Good Luck!


    I tried the code and I am getting the following message:


    Cannot run the macro "simple-timer-test-blink-code.xlsm'!startStopTimer'. The macro may not be available in this workbook or all macros may be disabled.


    I attached the workbook. If you have time could you take a look and see if anything jumps out that I could be doing wrong?


    Kind regards,
    yeto

  • You need to make the "button" the activex version not the forms version.



    here!

  • You need to make the "button" the activex version not the forms version.



    here!


    Thank you. Thank you. That worked great. You are a genius my friend.


    I am going to work with the other code as well to see if I can get it to work. The more things I try the more I learn. As I am new at VBA this has been a great learning experience. I am not sure if I should use a shape button or a form button for the other code but I will try both.


    Again, thank you for taking time out of your day to help me.


    Kind regards,
    yeto

  • No matter what I do I can't get the second code to run. I tried a shape, a form and an activex button and it won't work for me. I Googled how to assign a button and studied some tutorials but I still can't get the second code to work. I am sure there is something simple I am doing wrong but I can't figure it out. I may need some more help.


    I have attached what I have done so far.


    Kind regards,
    yeto

  • Not sure what you're doing here. Seems like you're trying to replicate, on your own, the wrkbook I sent back? There is no code in a .xlsx file. But you did not name the activex command button object.

  • Not sure what you're doing here. Seems like you're trying to replicate, on your own, the wrkbook I sent back? There is no code in a .xlsx file. But you did not name the activex command button object.


    Oh...I think I understand now. It takes both of the codes you shared earlier to make the stopwatch work. I was thinking that they were 2 separate codes. One would work with an activex button and the other would work with a form or shape button. Is my line of thinking now correct? It takes both codes and it will only work with an activex button?

  • You need to make the "button" the activex version not the forms version.



    here!


    I used the timer today and it definitely works but when I deleted the dates and times and started a new set of dates and times the timer starts in the location it last used. It does not go back to the top of the spreadsheet. Is it possible to somehow reset the timer so it starts back at the top?


    Kind regards,
    yeto

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!