excelperfect
今天正月初一,给各位朋友拜年啦!
新年新气象,2021牛起来!
下面是两段用于绘制形状的小程序:绘制任意形状;绘制箭头线。
绘制任意形状的代码:
代码语言:javascript复制Sub MakeArch()
Dim oFFB As FreeformBuilder
'创建新的任意形状
Set oFFB =ActiveSheet.Shapes.BuildFreeform(msoEditingCorner, 100, 300)
'添加线条到创建的形状中
With oFFB
.AddNodes msoSegmentLine,msoEditingAuto, 100, 200
.AddNodes msoSegmentCurve,msoEditingCorner, 150, 150, 0, 0, 200, 200
.AddNodes msoSegmentLine,msoEditingAuto, 200, 300
.AddNodes msoSegmentLine,msoEditingAuto, 100, 300
'将其转换为形状
.ConvertToShape
End With
End Sub
绘制箭头线的代码:
代码语言:javascript复制Sub AddAndFormatLine()
Dim oShp As Shape
Dim oLF As LineFormat
'添加线条形状
Set oShp = ActiveSheet.Shapes.AddLine(100,100, 200, 250)
'获得线条格式对象
Set oLF = oShp.Line
'设置线条格式
With oLF
.BeginArrowheadStyle = msoArrowheadOval
.EndArrowheadStyle =msoArrowheadTriangle
.EndArrowheadLength = msoArrowheadLong
.EndArrowheadWidth = msoArrowheadWide
.Style = msoLineSingle
End With
End Sub
你可以修改其中的参数值,来灵活绘制形状和箭头。
注:由于疏忽,先推送了VBA实用小程序69,将VBA实用小程序67和68漏掉了,这两天陆续补上。谢谢有心人“深海”朋友的提醒!
欢迎在下面留言,完善本文内容,让更多的人学到更完美的知识。