Draw a star : Shapes « Excel « VBA / Excel / Access / Word






Draw a star

 
Private Sub btnStar_Click()
  Dim degree#
  Dim s As Shape
  Const Pi = 3.1415927
  Randomize
  For degree = 0 To 2 * Pi Step Pi / 12
    Set s = ActiveSheet.Shapes.AddLine(200, 200, 200 + 100 * Sin(degree), 200 + 100 * Cos(degree))
    s.Line.EndArrowheadStyle = msoArrowheadTriangle
    s.Line.EndArrowheadLength = msoArrowheadLengthMedium
    s.Line.EndArrowheadWidth = msoArrowheadWidthMedium
    s.Line.ForeColor.RGB = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
  Next
End Sub

 








Related examples in the same category

1.Add a rectangle
2.Display auto shapes
3.Add a new shape
4.Delete all shapes