VBA - Colour change buttons with timer

Jasesair

Active Member
Joined
Apr 8, 2015
Messages
282
Office Version
  1. 2016
I am wanting to utilise colour changing buttons to essentially highlight a button when pressed. After 1 or 2 seconds, I'd like the button to revert back to the original colour. Is this possible? This is what I have so far...

VBA Code:
Sub SetColor(v)
  Dim cell As String
  cell = ActiveCell.Address
  ActiveSheet.Shapes.SelectAll
  Selection.ShapeRange.Fill.ForeColor.RGB = RGB(175, 171, 171)
  ActiveSheet.Shapes(v).Fill.ForeColor.RGB = RGB(0, 204, 153)
  Range(cell).Activate
End Sub

VBA Code:
Sub Offerings1()

    Application.ScreenUpdating = False
    Call SetColor(Application.Caller)

    Worksheets("Offerings").Range("c7,e7,g7,i7").Interior.ColorIndex = xlNone

End Sub
 
I'm assuming that you've declared buttonColor as Long, and that you've placed it in a regular module, correct?
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Yep, this is what's in a regular module:

VBA Code:
Option Explicit

Public button As Shape
Public buttonColor As Long

Public Sub ResetButton(ByVal button As Shape, ByVal buttonColor As Long)

    buttonColor = button.Fill.ForeColor.RGB
    
End Sub
 
Upvote 0
Try running the code again. This time, though, when the error occurs on that line, enter the following two lines separately in the Immediate Window [Ctrl+G]...

VBA Code:
? buttonColor

VBA Code:
? button.Fill.ForeColor.RGB

What do these two statements return?
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,660
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top