woodportaj
New Member
- Joined
- Jan 22, 2021
- Messages
- 5
- Office Version
- 2016
- Platform
- Windows
I am trying to create a code for a toggle button. I want a circle to appear around the button when it is clicked, and I want the circle to be deleted or hidden when the button is clicked again. I'm VERY VERY new to this. I thought I had it but I keep getting an error. This is what I have so far.....
Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
'when the toggle button is not depressed
ActiveSheet.Shapes.AddShape(msoShapeOval, 3, 364.5, 90.75, 40.5).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
Selection.ShapeRange.Fill.Visible = msoFalse
With Selection.ShapeRange.Line
.Visible = msoTrue
.Weight = 2.25
End With
Selection.ShapeRange.ZOrder msoBringToFront
Else
'when the toggle button is depressed
Dim Sh As Shape
For Each Sh In ActiveSheet.Shapes
If Not Application.Intersect(Sh.TopLeftCell, Range("C6:D7")) Is Nothing Then
Sh.Delete
End If
End Sub
Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
'when the toggle button is not depressed
ActiveSheet.Shapes.AddShape(msoShapeOval, 3, 364.5, 90.75, 40.5).Select
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
Selection.ShapeRange.Fill.Visible = msoFalse
With Selection.ShapeRange.Line
.Visible = msoTrue
.Weight = 2.25
End With
Selection.ShapeRange.ZOrder msoBringToFront
Else
'when the toggle button is depressed
Dim Sh As Shape
For Each Sh In ActiveSheet.Shapes
If Not Application.Intersect(Sh.TopLeftCell, Range("C6:D7")) Is Nothing Then
Sh.Delete
End If
End Sub