Option Explicit
Option Private Module
Public Function CreateFakeToggleButton( _
ByVal Name As String, _
ByVal ParentSheet As Worksheet, _
ByVal Left As Single, _
ByVal Top As Single, _
ByVal Width As Single, _
ByVal Height As Single, _
ByVal Caption As String, _
ByVal OnActionMacro As String _
) As Shape
Dim oShape As Shape
Set oShape = ParentSheet.Shapes.AddShape(msoShapeRectangle, Left, Top, Width, Height)
With oShape
.Name = Name
.AlternativeText = "Not-Pressed"
.OnAction = OnActionMacro
.Line.Visible = msoFalse
With .Fill.ForeColor
.ObjectThemeColor = msoThemeColorBackground1
.Brightness = -0.05
End With
With .Shadow
.Type = msoShadow25
.Visible = msoTrue
.Style = msoShadowStyleInnerShadow
.Transparency = 0.5
.OffsetX = 1.5
.OffsetY = 1.31
End With
With .TextFrame2
.TextRange.Text = Caption
.TextRange.Font.Bold = msoTrue
.TextRange.Characters.Font.Fill.ForeColor.RGB = RGB(0, 0, 0)
.VerticalAnchor = msoAnchorMiddle
.HorizontalAnchor = msoAnchorCenter
End With
End With
Set CreateFakeToggleButton = oShape
End Function
Public Sub OnActionMacro()
With ActiveSheet.Shapes(Application.Caller)
If ToggleButtonValue(ActiveSheet.Shapes(Application.Caller)) Then
MsgBox "(" & .Name & ")" & vbNewLine & vbNewLine & "Was Pressed."
Else
MsgBox "(" & .Name & ")" & vbNewLine & vbNewLine & "Was Not Pressed."
End If
End With
End Sub
Private Function ToggleButtonValue(ByVal Shp As Shape) As Boolean
With Shp
.Shadow.Type = msoShadow25
.Shadow.Visible = msoTrue
.Shadow.Style = msoShadowStyleInnerShadow
.Shadow.Transparency = 0.5
If .AlternativeText = "Not-Pressed" Then
.AlternativeText = "Pressed"
.Shadow.OffsetX = -1.5
.Shadow.OffsetY = -1.31
Else
.AlternativeText = "Not-Pressed"
.Shadow.OffsetX = 1.5
.Shadow.OffsetY = 1.31
End If
End With
Call Delay(0.1)
ToggleButtonValue = IIf(Shp.AlternativeText = "Not-Pressed", True, False)
End Function
Private Sub Delay(ByVal HowLong As Single)
Dim t As Single
t = Timer
Do
DoEvents
Loop Until Timer - t >= HowLong
End Sub