JohnZ1156
Board Regular
- Joined
- Apr 10, 2021
- Messages
- 180
- Office Version
- 2021
- Platform
- Windows
I have a "toggle" command button, and it works great.
The only thing missing is that I'd like the button color to toggle from Red to Green.
Here is my VBA Code, note that I tried to place the code ".BackColor = vbRed" and ".BackColor = vbGreen" in various places within the macro.
I commented them out because I keep getting a Debug message.
Thank you.
The only thing missing is that I'd like the button color to toggle from Red to Green.
Here is my VBA Code, note that I tried to place the code ".BackColor = vbRed" and ".BackColor = vbGreen" in various places within the macro.
I commented them out because I keep getting a Debug message.
Thank you.
VBA Code:
Private Sub ToggleMacro()
'Simplify code by refering to object once
With ActiveSheet.Shapes("Button1").TextFrame.Characters
'Check if button text is equal to a specific string.
If .Text = "VOID Check" Then
Dim ws As Worksheet
Dim rng As Range
Set ws = Sheets("Sheet1")
Set rng = ws.Range("K16:K19")
[B]' Button1.BackColor = vbRed[/B]
With ws.Shapes("Picture 3")
.LockAspectRatio = msoFalse
.Top = rng.Top
.Left = rng.Left
.Height = rng.Height
.Width = rng.Width
[B]' .BackColor = vbRed[/B]
End With
'Change button text.
.Text = "Do Not VOID Check"
[B]' .BackColor = vbRed[/B]
'This happens if button text is not equal to the specific string.
Else
Set ws = Sheets("Sheet1")
Set rng = ws.Range("B16:d20")
With ws.Shapes("Picture 3")
.LockAspectRatio = msoFalse
.Top = rng.Top
.Left = rng.Left
.Height = rng.Height
.Width = rng.Width
[B]' .BackColor = vbGreen[/B]
End With
'Change button text.
.Text = "VOID Check"
[B]' .BackColor = vbGreen[/B]
End If
End With
End Sub