【问题标题】:VBA How can I repeat code on every slide to edit the FIRST text box?VBA 如何在每张幻灯片上重复代码以编辑第一个文本框?
【发布时间】:2016-06-06 20:42:06
【问题描述】:

我正在为 Powerpoint 编写一个 VB 代码。它从幻灯片上的 SECOND 文本框中检索日期并计算距离该日期的天数。然后计算的天数显示在第一个文本框中。尽管文本框的名称与第一张幻灯片相同,但我无法为第二张幻灯片重复代码。

'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

【问题讨论】:

    标签: excel vba loops powerpoint simpledateformat


    【解决方案1】:

    试试这样的:

    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
    

    【讨论】:

    • 工作,谢谢!我将不得不研究 OLEFormat .. 你知道如何延迟五秒钟吗?睡眠对我不起作用。再次感谢
    • 我用下面这个作为定时器... Start = TimerWhile Timer &lt; Start + 5 DoEventsWend
    • 只是为了填补一两个空白:当您在幻灯片上有一个 ActiveX 控件时,该形状的 OLEFormat.Object 使您可以访问从表单上的相同形状获得的相同属性.不幸的是,Intellisense 无法提供帮助,但您可以右键单击该形状并选择“属性”以查看可用的属性以及它们的名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    相关资源
    最近更新 更多