Option Explicit
Dim startX As Integer, startY As Integer, i As Integer, j As Integer, digitCnt As String
Dim WSNew As Worksheet
Const InitialstartX As Integer = 600, InitialstartY As Integer = 100
Sub NEWNUMBER()
Do 'input for number of digits
digitCnt = InputBox("Enter number of digits to be generated.", Default:=3)
If digitCnt = "" Then Exit Sub
digitCnt = CInt(digitCnt)
Loop Until digitCnt > 0 And digitCnt < 8
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
Set WSNew = ActiveWorkbook.ActiveSheet
ActiveWindow.DisplayGridlines = False
startX = InitialstartX
startY = InitialstartY
j = 1
For i = 1 To digitCnt 'total number of digits
If i = 2 Then 'POINT
With WSNew.Shapes.AddShape(msoShapeRectangle, InitialstartX - 23, InitialstartY + 138, 12, 12)
.Name = "POINT"
.Fill.ForeColor.RGB = vbRed
.Line.Transparency = 1
.Placement = 3
End With
j = j + 1
End If
If i = 4 Then 'Minutes Separator
With WSNew.Shapes.AddShape(msoShapeRectangle, startX + 60, InitialstartY + 110, 12, 12)
.Name = "TOPSEP1"
.Fill.ForeColor.RGB = vbRed
.Line.Transparency = 1
.Placement = 3
End With
With WSNew.Shapes.AddShape(msoShapeRectangle, startX + 60, InitialstartY + 40, 12, 12)
.Name = "BTMSEP1"
.Fill.ForeColor.RGB = vbRed
.Line.Transparency = 1
.Placement = 3
End With
j = j + 2
End If
If i = 6 Then 'Hours Separator
With WSNew.Shapes.AddShape(msoShapeRectangle, startX + 60, InitialstartY + 110, 12, 12)
.Name = "TOPSEP2"
.Fill.ForeColor.RGB = vbRed
.Line.Transparency = 1
.Placement = 3
End With
With WSNew.Shapes.AddShape(msoShapeRectangle, startX + 60, InitialstartY + 40, 12, 12)
.Name = "BTMSEP2"
.Fill.ForeColor.RGB = vbRed
.Line.Transparency = 1
.Placement = 3
End With
j = j + 2
End If
'TOP1
With WSNew.Shapes.BuildFreeform(msoEditingCorner, startX, startY)
.AddNodes msoSegmentLine, msoEditingAuto, startX + 50, startY
.AddNodes msoSegmentLine, msoEditingAuto, startX + 50, startY + 5
.AddNodes msoSegmentLine, msoEditingAuto, startX + 40, startY + 15
.AddNodes msoSegmentLine, msoEditingAuto, startX + 10, startY + 15
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY + 5
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY
.ConvertToShape
End With
With WSNew.Shapes(j)
.Name = "TOP" & i
.Line.Transparency = 1
.Placement = 3
With .Fill
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
j = j + 1
'MIDDLE1
startX = startX - 3
startY = startY + 74
With WSNew.Shapes.BuildFreeform(msoEditingCorner, startX + 4, startY - 1)
.AddNodes msoSegmentLine, msoEditingAuto, startX + 12, startY - 9
.AddNodes msoSegmentLine, msoEditingAuto, startX + 44, startY - 9
.AddNodes msoSegmentLine, msoEditingAuto, startX + 52, startY - 1
.AddNodes msoSegmentLine, msoEditingAuto, startX + 52, startY + 1
.AddNodes msoSegmentLine, msoEditingAuto, startX + 44, startY + 9
.AddNodes msoSegmentLine, msoEditingAuto, startX + 12, startY + 9
.AddNodes msoSegmentLine, msoEditingAuto, startX + 4, startY + 1
.AddNodes msoSegmentLine, msoEditingAuto, startX + 4, startY - 1
.ConvertToShape
End With
With WSNew.Shapes(j)
.Name = "MIDDLE" & i
.Line.Transparency = 1
.Placement = 3
With .Fill
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
j = j + 1
'BOTTOM1
startX = startX + 3
startY = startY + 59
With WSNew.Shapes.BuildFreeform(msoEditingCorner, startX, startY)
.AddNodes msoSegmentLine, msoEditingAuto, startX + 50, startY
.AddNodes msoSegmentLine, msoEditingAuto, startX + 50, startY + 5
.AddNodes msoSegmentLine, msoEditingAuto, startX + 40, startY + 15
.AddNodes msoSegmentLine, msoEditingAuto, startX + 10, startY + 15
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY + 5
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY
.ConvertToShape
End With
With WSNew.Shapes(j)
.Flip msoFlipVertical
.Name = "BOTTOM" & i
.Line.Transparency = 1
.Placement = 3
With .Fill
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
j = j + 1
'LEFTTOP1
startX = startX - 6
startY = startY - 127
With WSNew.Shapes.BuildFreeform(msoEditingCorner, startX, startY)
.AddNodes msoSegmentLine, msoEditingAuto, startX + 5, startY
.AddNodes msoSegmentLine, msoEditingAuto, startX + 15, startY + 10
.AddNodes msoSegmentLine, msoEditingAuto, startX + 15, startY + 57
.AddNodes msoSegmentLine, msoEditingAuto, startX + 5, startY + 67
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY + 67
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY
.ConvertToShape
End With
With WSNew.Shapes(j)
.Name = "LEFTTOP" & i
.Line.Transparency = 1
.Placement = 3
With .Fill
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
j = j + 1
'LEFTBOTTOM1
startX = startX
startY = startY + 69
With WSNew.Shapes.BuildFreeform(msoEditingCorner, startX, startY)
.AddNodes msoSegmentLine, msoEditingAuto, startX + 5, startY
.AddNodes msoSegmentLine, msoEditingAuto, startX + 15, startY + 10
.AddNodes msoSegmentLine, msoEditingAuto, startX + 15, startY + 57
.AddNodes msoSegmentLine, msoEditingAuto, startX + 5, startY + 67
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY + 67
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY
.ConvertToShape
End With
With WSNew.Shapes(j)
.Name = "LEFTBOTTOM" & i
.Line.Transparency = 1
.Placement = 3
With .Fill
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
j = j + 1
'RIGHTTOP1
startX = startX + 47
startY = startY - 69
With WSNew.Shapes.BuildFreeform(msoEditingCorner, startX, startY)
.AddNodes msoSegmentLine, msoEditingAuto, startX + 5, startY
.AddNodes msoSegmentLine, msoEditingAuto, startX + 15, startY + 10
.AddNodes msoSegmentLine, msoEditingAuto, startX + 15, startY + 57
.AddNodes msoSegmentLine, msoEditingAuto, startX + 5, startY + 67
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY + 67
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY
.ConvertToShape
End With
With WSNew.Shapes(j)
.Flip msoFlipHorizontal
.Name = "RIGHTTOP" & i
.Line.Transparency = 1
.Placement = 3
With .Fill
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
j = j + 1
'RIGHTBOTTOM1
startX = startX
startY = startY + 69
With WSNew.Shapes.BuildFreeform(msoEditingCorner, startX, startY)
.AddNodes msoSegmentLine, msoEditingAuto, startX + 5, startY
.AddNodes msoSegmentLine, msoEditingAuto, startX + 15, startY + 10
.AddNodes msoSegmentLine, msoEditingAuto, startX + 15, startY + 57
.AddNodes msoSegmentLine, msoEditingAuto, startX + 5, startY + 67
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY + 67
.AddNodes msoSegmentLine, msoEditingAuto, startX, startY
.ConvertToShape
End With
With WSNew.Shapes(j)
.Flip msoFlipHorizontal
.Name = "RIGHTBOTTOM" & i
.Line.Transparency = 1
.Placement = 3
With .Fill
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
j = j + 1
startX = startX - 125
startY = InitialstartY
Next i
'COMMAND & OPTION BUTTONS
With ActiveSheet.Shapes.AddShape(msoShapeRoundedRectangle, InitialstartX + 80, InitialstartY, 120, 30)
.ShapeStyle = msoShapeStylePreset25
.OnAction = "runTimer"
.Name = "StartBtn"
.Title = digitCnt
With .TextFrame2
.TextRange.Characters.Text = "START"
.TextRange.Characters.Font.Size = 16
.VerticalAnchor = msoAnchorMiddle
.HorizontalAnchor = msoAnchorCenter
End With
End With
With ActiveSheet.Shapes.AddShape(msoShapeRoundedRectangle, InitialstartX + 80, InitialstartY + 60, 120, 30)
.ShapeStyle = msoShapeStylePreset24
.OnAction = "stpTimer"
With .TextFrame2
.TextRange.Characters.Text = "STOP"
.TextRange.Characters.Font.Size = 16
.VerticalAnchor = msoAnchorMiddle
.HorizontalAnchor = msoAnchorCenter
End With
End With
WSNew.OLEObjects.Add ClassType:="Forms.OptionButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=InitialstartX + 100, Top:=InitialstartY + 110, _
Width:=120, Height:=30
WSNew.OLEObjects.Add ClassType:="Forms.OptionButton.1", _
Link:=False, DisplayAsIcon:=False, Left:=InitialstartX + 150, Top:=InitialstartY + 110, _
Width:=120, Height:=30
With ActiveSheet.OLEObjects("OptionButton1")
.Name = "LEDOpt"
.Object.AutoSize = True
.Object.Caption = "LED"
.Object.Value = True
End With
With ActiveSheet.OLEObjects("OptionButton2")
.Name = "LCDOpt"
.Object.AutoSize = True
.Object.Caption = "LCD"
.Object.Value = False
End With
End Sub