Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
值超出范围错误,vba ppt_Vba_Powerpoint - Fatal编程技术网

值超出范围错误,vba ppt

值超出范围错误,vba ppt,vba,powerpoint,Vba,Powerpoint,我正在用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"

我正在用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

请帮帮我

需要散列符号来分隔日期值

thedate = #12/25/2013#
它的顺序是mm/dd/yyyy

还要记住,VBA集合是从1索引的,因此形状(countOfShapes)将是最后一个形状。

您的代码:

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)将抛出一个错误

哪一行出现错误?您的演示文稿中有多少张幻灯片?尝试将日期更改为2013-12-25。。。尝试在所有
.TextRange
之后添加
.Text
属性。。。