您可以使用Shapes.Adjustments
属性来调整块弧的“长度”。
程序AdjustArc
将指定的形状设置为指定的“% 完全的".
程序Demo
将为您的形状进展“注入动画”。确保在运行演示之前根据需要更改工作表名称和形状名称。程序Pause
只是化妆品Demo
.
![](https://i.stack.imgur.com/5tJQy.gif)
Sub AdjustArc(arcShape As Shape, percent As Single)
'adjust the circumference of the arc or hides if 0%.
'Supply the percent as a fraction between 0 and 1. (50% = 0.5)
With arcShape
If percent <= 0 Then 'hide shape
.Visible = False
Exit Sub
End If
If percent > 1 Then percent = 1 'over 100%, make it 100%
.Visible = True
'0 = Full Circle, 359.9 = sliver, 360 = Full Circle
.Adjustments.Item(1) = (1 - percent) * 359.9
End With
End Sub
Sub demo() 'Run this one for demonstration
Dim ws As Worksheet, sh As Shape, x As Single
Set ws = ThisWorkbook.Sheets("Sheet1")
Set sh = ws.Shapes("Block Arc 1")
For x = 0 To 1 Step 0.005
AdjustArc sh, x
Pause 0.01
Next x
End Sub
Sub Pause(seconds As Single) 'just for the demo
'pause for specified number of seconds
Dim startTime As Single: startTime = Timer
Do: DoEvents: Loop Until Timer >= startTime + seconds
End Sub
简洁版本:
改变形状的线是:
ActiveSheet.Shapes("YourShapeName").Adjustments.Item(1) = x
...在哪里x
是一个值> 0 and < 360
.
Edit:适应您的代码
目前您的示例代码调用SizeCircle
当工作表的单元格 CT15 发生变化时。
您可以替换这一行:
Call SizeCircle("Block Arc 63", Val(Target.Value))
...用这个:
AdjustArc ThisWorkbook.Sheets("Sheet1").Shapes("Block Arc 63"),Val(Target.Value)
只需更换Sheet1
以及具有该形状的工作表的名称。
这是假设百分比是stored作为实际百分比(0 到 1)CT15
...它的格式如何并不重要。
你的代码和我的SizeCircle
程序应在工作表模块(因为它有一个 on_change 事件)您可以通过右键单击工作表的选项卡并单击View Code
.
更多信息:
- MSDN : 调整对象 (Excel)
- 堆栈溢出 :关于形状的很多内容(我的答案)
- 代码VBA:如何使用Excel类Shape
- MSDN : 形状对象 (Excel)