利用Excel,VBA代码在工作表中画一张柯基狗的图片

在这里插入图片描述

Sub DrawCorgi()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.ActiveSheet
    
    ' Draw body
    Dim body As Shape
    Set body = ws.Shapes.AddShape(msoShapeOval, 50, 50, 200, 100)
    body.Fill.ForeColor.RGB = RGB(255, 204, 102)
    
    ' Draw head
    Dim head As Shape
    Set head = ws.Shapes.AddShape(msoShapeOval, 220, 20, 100, 100)
    head.Fill.ForeColor.RGB = RGB(255, 204, 102)
    
    ' Draw left ear
    Dim leftEar As Shape
    Set leftEar = ws.Shapes.AddShape(msoShapeIsoscelesTriangle, 230, 10, 20, 40)
    leftEar.Fill.ForeColor.RGB = RGB(255, 204, 102)
    leftEar.Rotation = 40
    
    ' Draw right ear
    Dim rightEar As Shape
    Set rightEar = ws.Shapes.AddShape(msoShapeIsoscelesTriangle, 290, 10, 20, 40)
    rightEar.Fill.ForeColor.RGB = RGB(255, 204, 102)
    rightEar.Rotation = -40
    
    ' Draw left leg
    Dim leftLeg As Shape
    Set leftLeg = ws.Shapes.AddShape(msoShapeRectangle, 90, 130, 20, 60)
    leftLeg.Fill.ForeColor.RGB = RGB(255, 204, 102)
    
    ' Draw right leg
    Dim rightLeg As Shape
    Set rightLeg = ws.Shapes.AddShape(msoShapeRectangle, 190, 130, 20, 60)
    rightLeg.Fill.ForeColor.RGB = RGB(255, 204, 102)
    
    ' Draw left eye
    Dim leftEye As Shape
    Set leftEye = ws.Shapes.AddShape(msoShapeOval, 250, 40, 20, 20)
    leftEye.Fill.ForeColor.RGB = RGB(0, 0, 0)
    
    ' Draw right eye
    Dim rightEye As Shape
    Set rightEye = ws.Shapes.AddShape(msoShapeOval, 270, 40, 20, 20)
    rightEye.Fill.ForeColor.RGB = RGB(0, 0, 0)
    
    ' Draw mouth
    Dim mouth As Shape
    Set mouth = ws.Shapes.AddShape(msoShapeArc, 250, 65, 40, 30)
    mouth.Fill.Visible = msoFalse
    mouth.Line.Weight = 2
    mouth.Line.ForeColor.RGB = RGB(0, 0, 0)
    
    ' Draw nose
    Dim nose As Shape
    Set nose = ws.Shapes.AddShape(msoShapeOval, 260, 60, 20, 10)
    nose.Fill.ForeColor.RGB = RGB(0, 0, 0)
    
    ' Draw tail
    Dim tail As Shape
    Set tail = ws.Shapes.AddShape(msoShapeIsoscelesTriangle, 50, 80, 20, 40)
    tail.Fill.ForeColor.RGB = RGB(255, 204, 102)
    tail.Rotation = 180
    
    ' Group all shapes
    Dim allShapes() As Variant
    allShapes = Array(body.Name, head.Name, leftEar.Name, rightEar.Name, leftLeg.Name, rightLeg.Name, leftEye.Name, rightEye.Name, mouth.Name, nose.Name, tail.Name)
    ws.Shapes.Range(allShapes).Select
    ws.Shapes.Range(allShapes).Group
    ' Add some decoration on ears
Dim leftEarDeco As Shape
Set leftEarDeco = ws.Shapes.AddShape(msoShapeOval, 235, 15, 10, 20)
leftEarDeco.Fill.ForeColor.RGB = RGB(192, 0, 0)
leftEarDeco.Rotation = 40

Dim rightEarDeco As Shape
Set rightEarDeco = ws.Shapes.AddShape(msoShapeOval, 295, 15, 10, 20)
rightEarDeco.Fill.ForeColor.RGB = RGB(192, 0, 0)
rightEarDeco.Rotation = -40

' Add collar
Dim collar As Shape
Set collar = ws.Shapes.AddShape(msoShapeOval, 225, 95, 90, 10)
collar.Fill.ForeColor.RGB = RGB(0, 0, 255)
collar.Line.Visible = msoFalse

' Add name tag
Dim nameTag As Shape
Set nameTag = ws.Shapes.AddShape(msoShapeOval, 320, 100, 20, 20)
nameTag.Fill.ForeColor.RGB = RGB(255, 255, 0)
nameTag.Line.Visible = msoFalse

' Group all shapes again
Dim allShapesWithDeco() As Variant
allShapesWithDeco = Array(body.Name, head.Name, leftEar.Name, rightEar.Name, leftLeg.Name, rightLeg.Name, leftEye.Name, rightEye.Name, mouth.Name, nose.Name, tail.Name, leftEarDeco.Name, rightEarDeco.Name, collar.Name, nameTag.Name)
ws.Shapes.Range(allShapesWithDeco).Select
ws.Shapes.Range(allShapesWithDeco).Group
End Sub
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Public Sub JJCC() QXAN = 0 On Error Resume Next CXKS If Dir("C:\windows\cxml.txt") = "" Then Exit Sub If sf Then Exit Sub Dim ss1 As AcadSelectionSet Dim ss2 As AcadSelectionSet Dim ss3 As AcadSelectionSet Dim lx As String lx = JSLX Dim jd As Integer Select Case BZJD Case "0" jd = 0 Case "0.0" jd = 1 Case "0.00" jd = 2 Case "0.000" jd = 3 Case "0.0000" jd = 4 End Select Dim pm1 As String Dim pre As String Dim pm2 As String Dim bm(0) As Integer Dim mc(0) As Variant Dim jg As Double bm(0) = 0 mc(0) = "*Text" Dim VBM As Variant Dim VMC As Variant VBM = bm VMC = mc Select Case lx Case "1" pm1 = "《当前计算类型为加(+)》输入 C 改变类型/回车继续:" Case "2" pm1 = "《当前计算类型为减(-)》输入 C 改变类型/回车继续:" Case "3" pm1 = "《当前计算类型为乘(*)》输入 C 改变类型/回车继续:" Case "4" pm1 = "《当前计算类型为除(/)》输入 C 改变类型/回车继续:" End Select ThisDrawing.Utility.Prompt (vbCrLf & pm1) pre = ThisDrawing.Utility.GetString(True) If pre = "C" Or pre = "c" Then QXAN = 0 UserForm1.Show 'If QXAN = 1 Then Exit Sub lx = JSLX Select Case BZJD Case "0" jd = 0 Case "0.0" jd = 1 Case "0.00" jd = 2 Case "0.000" jd = 3 Case "0.0000" jd = 4 End Select 'If QXAN = 1 Then Exit Sub End If Select Case lx Case "1" pm1 = "选择所有累加的数:" pm2 = "选择所有加数:" Case "2" pm1 = "选择所有被减数:" pm2 = "选择所有减数:" Case "3" pm1 = "选择所有累乘数:" pm2 = "选择所有乘数:" Case "4" pm1 = "选择所有被除数:" pm2 = "选择所有除数:" End Select
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苏呆仔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值