我正在使用带有自定义幻灯片的PPT演示文稿。我找到了一种使用正确的幻灯片名称添加自定义幻灯片的方法。
我将其放在单独的 sub(addCustomSlides)中,因此我可以通过调用主模块并使用正确的名称布局名称来添加其主模块中的任何自定义幻灯片。
然后在主模块中,我想调用另一个 sub(addData)以添加其他信息。但这似乎根本不起作用。调用 sub(addData)时,它只会跳过以下内容:
等...
Sub testing() Dim pp As PowerPoint.Application Dim PPPres As PowerPoint.Presentation Dim PPSlide As PowerPoint.slide Dim Slidenumber As Integer Slidenumber = 1 Set pp = CreateObject("PowerPoint.Application") Set PPPres = pp.Presentations.Open(Filename:=Range("PPTtemplate_1").Text & Range("PPTtemplate_2").Text) Set PPSlide = PPPres.Slides.Add(1, ppLayoutTitleOnly) 'Standard layout that can be chosen PPSlide.Select PPSlide.Shapes("Title 1").TextFrame.TextRange.Text = "This is a new title" 'Changing text in the standard Titleblock Slidenumber = Slidenumber + 1 Call addCustomSlides(PPPres, Slidenumber, "Title and Subtitle") 'This is the customized slide Call addData(PPPres, Slidenumber) End Sub
Sub addCustomSlides(PPPres, Slidenumber, Layout) Dim PPSlide As PowerPoint.slide Dim SlideLayout As CustomLayout Set PPSlide = PPPres.Slides.Add(Slidenumber, ppLayoutBlank) For Each SlideLayout In PPPres.Designs(1).SlideMaster.CustomLayouts If SlideLayout.Name = Layout Then PPSlide.CustomLayout = SlideLayout Exit For End If Next PPSlide.Select PPSlide.Shapes("Title 2").TextFrame.TextRange.Text = "First call works" PPSlide.Shapes.AddTable(2, 2).Select End Sub
Sub addData(PPPres, Slidenumber) Dim PPSlide As PowerPoint.slide PPPres.Slides(Slidenumber).Select PPSlide.Shapes.AddTable(3, 3).Select PPSlide.Shapes("Title 2").TextFrame.TextRange.Text = "Second call works" End Sub
致电 2。 addCustomSlides 我可以轻松更改标题并为其添加表格。致电 3。 addData 我无法再更改标题或向其中添加表格。它只是无法识别演示文稿,因此无法更改或向幻灯片添加任何内容?