我在PowerPoint中进行循环演示,我需要倒计时到特定日期。
使用下面的代码时出现以下错误:
运行时错误'-2147024809(80070057)': 指定的值超出范围。
Sub Countdown()
Dim thedate As Date
Dim daycount As Long
Dim Icount As Integer
Icount = ActivePresentation.Slides(1).Shapes.Count - 1
thedate = "25/12/2013"
daycount = DateDiff("d", Now, thedate)
Select Case daycount
Case Is > 1
ActivePresentation.Slides(1).Shapes(Icount) _
.TextFrame.TextRange = daycount & " Days to go!"
Case Is = 1
ActivePresentation.Slides(1).Shapes(Icount) _
.TextFrame.TextRange = daycount & " Day to go!"
Case Else
ActivePresentation.Slides(1).Shapes(Icount) _
.TextFrame.TextRange = "It's here!"
End Select
End Sub
请帮助我!
答案 0 :(得分:0)
您需要使用哈希符号来分隔日期值
thedate = #12/25/2013#
,它的顺序为mm / dd / yyyy。
还要记住,VBA集合的索引是1,因此Shapes(countOfShapes)将是最后一个Shape。
答案 1 :(得分:0)
您的代码:
Icount = ActivePresentation.Slides(1).Shapes.Count - 1
.....
Select Case daycount
Case Is > 1
ActivePresentation.Slides(1).Shapes(Icount) _
如果幻灯片上只有一个形状,则ICount将为0 ActivePresentation.Slides(1).Shapes(Icount)将抛出错误