简体   繁体   English

VBA如何在每张幻灯片上重复代码以编辑“第一个”文本框?

[英]VBA How can I repeat code on every slide to edit the FIRST text box?

I am writing a VB code for Powerpoint. 我正在为Powerpoint编写VB代码。 It retrieves a date from the SECOND Text box on the slide and calculates the amount of days until this date. 它从幻灯片的“第二个文本”框中检索日期,并计算到该日期为止的天数。 Then the calculated amount of days is shown in the FIRST text box. 然后,计算出的天数将显示在“第一”文本框中。 I can not get the code to repeat for the second slide, although the textboxes are named the same thing as the first slide. 尽管文本框与第一张幻灯片的名称相同,但我无法获得第二张幻灯片的代码重复。

'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

在此处输入图片说明

Try something like this instead: 尝试这样的事情:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM