【问题标题】:Populating Powerpoint slides from Access VBA从 Access VBA 填充 Powerpoint 幻灯片
【发布时间】:2013-12-02 11:29:32
【问题描述】:

我正在尝试使用以下代码在 powerpoint 文件中填充一些文本字段:

Private Sub OpenPPT_Click()

Dim pptPres As PowerPoint.Presentation
Dim pptApp As PowerPoint.Application
Dim currentSlide As Slide

Set pptApp = CreateObject("Powerpoint.Application")
Set pptPres = pptApp.Presentations.Open("C:\Users\Magda\Desktop\TestReport.pptx")
Set currentSlide = pptPres.Slides(pptPres.Slides.Count)

'Slide 1

currentSlide.Shapes("HomeTitle1").TextFrame.TextRange.Text = "This is the title"
currentSlide.Shapes("HomeTitle2").TextFrame.TextRange.Text = "This is the subtitle"

'Slide 2

currentSlide.Shapes("MainTitle1").TextFrame.TextRange.Text = "This is the title"
currentSlide.Shapes("Contents1").TextFrame.TextRange.Text = "Section1"
currentSlide.Shapes("Contents2").TextFrame.TextRange.Text = "Section2"
currentSlide.Shapes("Contents3").TextFrame.TextRange.Text = "Section3"
currentSlide.Shapes("Contents4").TextFrame.TextRange.Text = "Section4"

'Slide 3

currentSlide.Shapes("MainTitle2").TextFrame.TextRange.Text = "Section1"

End Sub

我的问题是这段代码似乎只在幻灯片 3(PPT 中的最后一张幻灯片)中设置了文本。我如何循环播放幻灯片以便填充每个幻灯片?

【问题讨论】:

    标签: vba ms-access for-loop powerpoint


    【解决方案1】:

    以下代码适用于我,循环播放每张幻灯片(Access 2010 操纵 PowerPoint 2010):

    Option Compare Database
    Option Explicit
    
    Sub pptTest()
        Dim pptApp As New PowerPoint.Application
        Dim pptPres As PowerPoint.Presentation
        Dim currentSlide As Slide
        Dim i As Long
    
        Set pptPres = pptApp.Presentations.Open("C:\Users\Gord\Desktop\TestReport.pptx")
        For i = 1 To pptPres.Slides.Count
            Set currentSlide = pptPres.Slides(i)
            Debug.Print currentSlide.Name
        Next
        Set currentSlide = Nothing
        pptPres.Close
        Set pptPres = Nothing
        pptApp.Quit
        Set pptApp = Nothing
    End Sub
    

    当然,如果您需要对每张幻灯片做些许不同的事情,您可以这样做

    Set currentSlide = pptPres.Slides(1)
    ' do stuff for Slide 1
    
    Set currentSlide = pptPres.Slides(2)
    ' do stuff for Slide 2
    
    ' and so on
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-11
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-15
      相关资源
      最近更新 更多