庆国庆VBA画一红旗

2022-10-25 13:57:36 浏览数 (1)

代码语言:javascript复制
Sub 画国旗(L, T, W, H)
    'Dim s1 As Shape
    Dim oWK As Worksheet
    Set oWK = Excel.ActiveSheet
    '插入一个半径为25Point的圆
    s1_L = L   (W / 30) * 5
    s1_T = T   (H / 20) * 5
    
    Set s0 = oWK.Shapes.AddShape(msoShapeRectangle, L, T, W, H)
    
    s0.Fill.ForeColor.RGB = RGB(255, 0, 0)
    Set s1 = oWK.Shapes.AddShape(msoShape5pointStar, L   (W / 30) * 2, T   (H / 20) * 2, H * 0.3, H * 0.3)
    s1.Fill.ForeColor.RGB = RGB(255, 255, 0)
    Set s2 = oWK.Shapes.AddShape(msoShape5pointStar, L   (W / 30) * 9, T   (H / 20) * 1, H * 0.1, H * 0.1)
    s2.Fill.ForeColor.RGB = RGB(255, 255, 0)
    s2.ThreeD.RotationZ = -50
    Set s3 = oWK.Shapes.AddShape(msoShape5pointStar, L   (W / 30) * 11, T   (H / 20) * 3, H * 0.1, H * 0.1)
    s3.Fill.ForeColor.RGB = RGB(255, 255, 0)
    s3.ThreeD.RotationZ = -25
    Set s4 = oWK.Shapes.AddShape(msoShape5pointStar, L   (W / 30) * 11, T   (H / 20) * 6, H * 0.1, H * 0.1)
    s4.Fill.ForeColor.RGB = RGB(255, 255, 0)
    Set s5 = oWK.Shapes.AddShape(msoShape5pointStar, L   (W / 30) * 9, T   (H / 20) * 8, H * 0.1, H * 0.1)
    s5.Fill.ForeColor.RGB = RGB(255, 255, 0)
    s5.ThreeD.RotationZ = 10
    s0.Line.Visible = msoFalse
    s1.Line.Visible = msoFalse
    s2.Line.Visible = msoFalse
    s3.Line.Visible = msoFalse
    s4.Line.Visible = msoFalse
    s5.Line.Visible = msoFalse
    ActiveSheet.Shapes.Range(Array(s0.Name, s1.Name, s2.Name, s3.Name, s4.Name, s5.Name)).Select
    Selection.ShapeRange.Group.Select
End Sub
Sub cl()
    Call 画国旗(Selection.Left, Selection.Top, 450, 300)
End Sub

本代码是个人学习,

可以你选中的位置画一个450,300大小 的国旗

学习知识:

  1. Shapes.AddShape方法
  2. shapes对象的填充,线条
  3. shapes多对象的组合
  4. 各对象之间的位置关系

0 人点赞