我正在为Powerpoint编写VB代码。它从幻灯片上的“第二个文本”框中检索日期,并计算此日期之前的天数。然后计算的天数显示在FIRST文本框中。虽然文本框的名称与第一张幻灯片的名称相同,但我无法获得第二张幻灯片重复的代码。
'Sets variables
Dim Sdate As Long
Dim thedate As Date
Dim txt As Date
Dim pptSlide3 As Slide
Do
For Each pptSlide3 In ActivePresentation.Slides
Set sld = ActivePresentation.SlideShowWindow.View.Slide
'Retrieves D-Day from corresponding text box
TextBox2.Font.Size = 36
thedate = TextBox2.Text
'Calculates the amount of time from today's date until D-day above
Sdate = DateDiff("d", Now(), thedate)
'Creates textbox with the value of how many days are left
TextBox1.Value = Sdate & " Days to go!"
TextBox1.Font.Size = 36
'Want it to wait 5 seconds here
' Goes to next slide
With SlideShowWindows(1).View
If sld.SlideIndex < 4 Then
.GotoSlide (sld.SlideIndex + 1)
End If
If sld.SlideIndex = 4 Then
.GotoSlide (1)
End If
End With
Next pptSlide3
Loop
答案 0 :(得分:0)
尝试这样的事情:
Do
For Each pptSlide3 In ActivePresentation.Slides
'Retrieves D-Day from corresponding text box
TextBox2.Font.Size = 36
thedate = pptSlide3.Shapes("TextBox2").OLEFormat.Object.Text
'Calculates the amount of time from today's date until D-day above
Sdate = DateDiff("d", Now(), thedate)
'Creates textbox with the value of how many days are left
pptSlide3.Shapes("TextBox1").OLEFormat.Object.Text = Sdate & " Days to go!"
TextBox1.Font.Size = 36
'Want it to wait 5 seconds here
' Goes to next slide
With SlideShowWindows(1).View
If pptSlide3.SlideIndex < 4 Then
.GotoSlide (pptSlide3.SlideIndex + 1)
End If
If pptSlide3.SlideIndex = 4 Then
.GotoSlide (1)
End If
End With
Next pptSlide3
Loop