網路城邦
回本城市首頁 唐老鴨之家
市長:  副市長:
加入本城市推薦本城市加入我的最愛訂閱最新文章
udn城市資訊科技網路分享【唐老鴨之家】城市/討論區/
討論區Excel VBA 字體:
上一個討論主題 回文章列表 下一個討論主題
繪製中華民國國旗的VBA程式(原創)
 瀏覽1,075|回應0推薦1


等級:6
留言加入好友
文章推薦人 (1)

龍女CHANG, HSIU-FEN

Private Sub CommandButton1_Click()
Rem draw the red block
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 0, 0, 400, 300).Select
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 2
Selection.ShapeRange.Line.ForeColor.SchemeColor = 2

Rem draw the blue block
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 0, 0, 200, 150).Select
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 4
Selection.ShapeRange.Line.ForeColor.SchemeColor = 4

Rem draw the 12 light
r1 = 400 / 6
r2 = 400 / 12
ww = 400 / 4
hh = 300 / 4
For i = 1 To 12
theta = i * 6.283 / 12
X1 = ww + r2 * Cos(theta + 6.283 / 24)
Y1 = hh + r2 * Sin(theta + 6.283 / 24)
X2 = ww + r1 * Cos(theta + 6.283 / 12)
Y2 = hh + r1 * Sin(theta + 6.283 / 12)
X3 = ww + r2 * Cos(theta + 6.283 / 8)
Y3 = hh + r2 * Sin(theta + 6.283 / 8)
With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, X1, Y1)
.AddNodes msoSegmentLine, msoEditingAuto, X2, Y2
.AddNodes msoSegmentLine, msoEditingAuto, X3, Y3
.AddNodes msoSegmentLine, msoEditingAuto, X1, Y1
.ConvertToShape.Select
End With
Selection.ShapeRange.Line.ForeColor.SchemeColor = 9
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 9
Next i

Rem draw the circle
ActiveSheet.Shapes.AddShape(msoShapeOval, 66, 42, r1, r1).Select
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 9
Selection.ShapeRange.Line.Weight = 5
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.ForeColor.SchemeColor = 4
End Sub

本文於 修改第 1 次
回應 回應給此人 推薦文章 列印 加入我的文摘

引用
引用網址:https://city.udn.com/forum/trackback.jsp?no=58536&aid=4752757