|
非常感谢9楼的解答!一直以为duration只控制整个对象的动画长度,殊不知原来定义为字母动画后就是定义每个字母的动画长度了。
在此基础上,因为ADDEFFECT不能自动运行,需要加入一个隐形的形状引导需要显示的动画。隐形形状的动画设为自动,而字母旋转动画跟随上一个动画播放。
在此还要感谢9楼的解答。因为FOR EACH循环好像不能删除没有线条和填充的形状,只能用FOR NEXT删除。
但是我个人不喜欢在循环内调用对象,而比较喜欢使用简单的变量以增加速度。
不过9楼的变量定义有误,不知道是不是因为开头没有Option Explicit呢。
改进后的完整代码如下:
Option Explicit
Private r As Integer, g As Integer, bl As Integer
Sub charEff()
Dim Sld As Slide, Shp As Shape, shp_tmp As Shape, h As Integer, text1$, text1_len As Byte, n%
Set Sld = ActiveWindow.Selection.SlideRange(1)
For n = Sld.Shapes.Count To 1 Step -1 '删除页面上的所有形状
Sld.Shapes(n).Delete
Next
Set Shp = Sld.Shapes.AddShape(msoShapeRoundedRectangle, 10, 25, 200, 100) '主要形状
Set shp_tmp = Sld.Shapes.AddShape(msoShapeRoundedRectangle, 4, 4, 4, 4) '需隐形的形状
With shp_tmp
.Line.Visible = msoFalse '让形状不可见,用shp_tmp.visible=msofalse会导致动画添加的失败
.Fill.Visible = msoFalse
End With
With Shp
.Name = "txtShp"
.Line.Visible = msoFalse
.Fill.Visible = msoFalse
With .TextFrame.TextRange
text1 = "3101 B2051" & vbCrLf & "08:00 201"
text1_len = Len(text1) '把字符串长度写入变量
.text = text1
.Font.Size = 24
.Font.Name = "Verdana"
For n = 1 To text1_len
If .Characters(n, 1) <> " " Then
h = 360 / text1_len * n
Call hsb2rgb(h, 0.8, 0.8)
.Characters(n, 1).Font.Color.RGB = RGB(r, g, bl)
End If
Next
End With
End With
With shp_tmp.AnimationSettings '为隐藏形状添加自动动画
.EntryEffect = ppEffectAppear
.AdvanceMode = ppAdvanceOnTime
.AdvanceTime = 0
.Animate = msoTrue
End With
With Sld.TimeLine.MainSequence '为主形状添加字母动画
.ConvertToTextUnitEffect .AddEffect(Shp, msoAnimEffectSwivel), msoAnimTextUnitEffectByCharacter '添加字母动画
.Item(2).Timing.Duration = 1 '如果程序将添加大量形状执行大量动画的时候,item(X)还需要另外求呢。
.Item(2).Timing.TriggerType = msoAnimTriggerAfterPrevious '设为跟随上一个动画播放
End With
End Sub
Sub hsb2rgb(h As Integer, s As Single, br As Single)
Dim hi As Integer, p As Single, q As Single, t As Single, f As Single, v As Single
v = br
If v = 0 Then r = g = bl = 0: Exit Sub
If s = 0 Then r = g = bl = v * 255: Exit Sub
hi = Int(h / 60)
f = h / 60 - hi
p = v * (1 - s)
q = v * (1 - s * f)
t = v * (1 - s * (1 - f))
Select Case hi
Case 0
r = v * 255: g = t * 255: bl = p * 255
Case 1
r = q * 255: g = v * 255: bl = p * 255
Case 2
r = p * 255: g = v * 255: bl = t * 255
Case 3
r = p * 255: g = q * 255: bl = v * 255
Case 4
r = t * 255: g = p * 255: bl = v * 255
Case 5
r = v * 255: g = p * 255: bl = q * 255
End Select
End Sub |
|