2013-07-16 88 views
0

我在PowerPoint中進行循環演示,我需要倒計時到特定日期。超出範圍錯誤,vba ppt

當使用代碼下面我得到以下錯誤:

運行時錯誤「-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 

請幫幫我!

+1

哪一行,你得到錯誤?你有多少張幻燈片?嘗試將'thedate'更改爲'2013-12-25' ...嘗試在所有'.TextRange'之後添加'.Text'屬性... –

回答

0

您需要哈希標誌,劃定一個時間值

thedate = #12/25/2013# 

,它是在訂單MM/DD/YYYY。

還要記住,VBA集合是從1索引的,所以Shapes(countOfShapes)將是最後一個Shape。

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)隨後將拋出一個錯誤