moonli 发表于 2017-6-23 16:56:44

都是优化惹的祸:VBA代码怠工没有动静

下面代码要实现的目标是:
在幻灯片放映模式下,母版中是否有一个叫做“进度条”的图形,没有就创建一个;有的话,就对其进行相应的操作,代码如下。
问题是:
1、有的话可以操作;
2、没有的话却不能创建。
Sub 幻灯片进度条()
'颜色1 = Array(vbRed, vbBlack, vbGreen, vbYellow, vbMagenta, vbBlue, vbCyan)
'颜色2 = Array(vbBlack, vbGreen, vbYellow, vbMagenta, vbBlue, vbCyan, vbRed)
'j = i Mod 7 + 1
Randomize
n = ActivePresentation.Slides.Count
i = ActivePresentation.SlideShowWindow.View.CurrentShowPosition
SlideMaster.Label1.Caption = "当 前" & vbCrLf & IIf(i = n, "结 束", i & "/" & n)
w = ActivePresentation.PageSetup.SlideWidth - 80
t = ActivePresentation.PageSetup.SlideHeight - 20
If ActivePresentation.SlideMaster.Shapes("进度条") Is Nothing Then
With ActivePresentation.SlideMaster.Shapes.AddShape(1, 72, t - 10, w * i / n, 30)
.Name = "进度条"
.Fill.BackColor.RGB = RGB(Int(255 * Rnd) + 1, Int(255 * Rnd) + 1, Int(255 * Rnd) + 1)
With .TextFrame.TextRange
.Text = Format(i / n, "0%")
.ParagraphFormat.Alignment = ppAlignRight
End With
.Fill.ForeColor.RGB = RGB(Int(255 * Rnd) + 1, Int(255 * Rnd) + 1, Int(255 * Rnd) + 1)
End With
Else
With ActivePresentation.SlideMaster.Shapes("进度条")
.Width = w * i / n
.Fill.BackColor.RGB = RGB(Int(255 * Rnd) + 1, Int(255 * Rnd) + 1, Int(255 * Rnd) + 1)
With .TextFrame.TextRange
.Text = Format(i / n, "0%")
.ParagraphFormat.Alignment = ppAlignRight
End With
.Fill.ForeColor.RGB = RGB(Int(255 * Rnd) + 1, Int(255 * Rnd) + 1, Int(255 * Rnd) + 1)
End With

End If
If i = n Then CreateObject("sapi.spvoice").speak "this is over!"
End Sub
该怎样修改才能创建这个图形?

leopard 发表于 2017-6-23 18:28:28

看来PPT VBA使用研究的人不多,否则早有答案了。
页: [1]
查看完整版本: 都是优化惹的祸:VBA代码怠工没有动静