如何在ExcelVBA中绘制带轮廓的楔形?
How to draw wedge shape with outline in Excel VBA?
我想在 Excel(Office 365 ProPlus 的桌面版)中使用 VBA 绘制一个圆的扇形(即楔形)。下面的代码给出了正确的形状,但只有弯曲部分的轮廓:
Dim myArc as Shape
Set myArc = ActiveSheet.Shapes.AddShape(msoShapeArc, 200, 100, 100, 100)
With myArc
.Adjustments(1) = 0
.Adjustments(2) = 45
.Fill.Visible = msoTrue
End With
直边没有轮廓,只有曲线。 如何在整个形状周围画出轮廓?我应该使用与 msoShapeArc
不同的形状吗?我试过使用下面的代码更改线条颜色、粗细和可见性,但它只影响弯曲的边缘,而不影响直线。
With myArc
.Line.ForeColor.RGB = RGB(0, 0, 0)
.Line.Weight = 1
.Line.Visible = msoTrue
End With
我已经能够找到有关一般形状属性的文档,但找不到哪些属性适用于哪种类型的形状,以及它们实际如何控制其外观。
根据https://docs.microsoft.com/en-us/office/vba/api/excel.adjustments:
Because each adjustable shape has a different set of adjustments, the
best way to verify the adjustment behavior for a specific shape is to
manually create an instance of the shape, make adjustments with the
macro recorder turned on, and then examine the recorded code.
这对我创建一个馅饼楔有用:
Sub WedgeTest()
Dim ws As Worksheet, shp As Shape
Set ws = ActiveSheet
Set shp = ws.Shapes.AddShape(msoShapePie, 50, 50, 100, 100)
With shp
.Adjustments.Item(1) = -90 'degrees from 3 oclock
.Adjustments.Item(2) = -45 'degrees from 3 oclock
.Fill.Visible = msoFalse
With .Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
End Sub
请注意从 3 点开始的度数是正(顺时针)或负(逆时针),但绝对值不能超过 180,因此顺时针 +190 度将设置为 -170(逆时针) .
我想在 Excel(Office 365 ProPlus 的桌面版)中使用 VBA 绘制一个圆的扇形(即楔形)。下面的代码给出了正确的形状,但只有弯曲部分的轮廓:
Dim myArc as Shape
Set myArc = ActiveSheet.Shapes.AddShape(msoShapeArc, 200, 100, 100, 100)
With myArc
.Adjustments(1) = 0
.Adjustments(2) = 45
.Fill.Visible = msoTrue
End With
直边没有轮廓,只有曲线。 如何在整个形状周围画出轮廓?我应该使用与 msoShapeArc
不同的形状吗?我试过使用下面的代码更改线条颜色、粗细和可见性,但它只影响弯曲的边缘,而不影响直线。
With myArc
.Line.ForeColor.RGB = RGB(0, 0, 0)
.Line.Weight = 1
.Line.Visible = msoTrue
End With
我已经能够找到有关一般形状属性的文档,但找不到哪些属性适用于哪种类型的形状,以及它们实际如何控制其外观。
根据https://docs.microsoft.com/en-us/office/vba/api/excel.adjustments:
Because each adjustable shape has a different set of adjustments, the best way to verify the adjustment behavior for a specific shape is to manually create an instance of the shape, make adjustments with the macro recorder turned on, and then examine the recorded code.
这对我创建一个馅饼楔有用:
Sub WedgeTest()
Dim ws As Worksheet, shp As Shape
Set ws = ActiveSheet
Set shp = ws.Shapes.AddShape(msoShapePie, 50, 50, 100, 100)
With shp
.Adjustments.Item(1) = -90 'degrees from 3 oclock
.Adjustments.Item(2) = -45 'degrees from 3 oclock
.Fill.Visible = msoFalse
With .Line
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
End Sub
请注意从 3 点开始的度数是正(顺时针)或负(逆时针),但绝对值不能超过 180,因此顺时针 +190 度将设置为 -170(逆时针) .