我正在尝试从 Excel(VBA)创建一个 powerpoint(带模板)并为每张幻灯片添加一个文本框。
我想在其中添加文本框的代码行失败,索引超出范围/没有活动演示。这里有什么问题?幻灯片的索引应该没问题 - 如果我手动设置索引没有任何变化。
Dim PowerPointApp As Object
Set PowerPointApp = CreateObject("PowerPoint.Application")
PowerPointApp.Visible = True
Set objP = PowerPointApp.Presentations.Add
objP.ApplyTemplate "" & Table1.Range("A1").Value & "draft.pptx"
PowerPointApp.ActivePresentation.Slides.Add 1, ppLayoutTitle
For i = 1 To 10
objP.ApplyTemplate "" & Table2.Range("A1").Value & "template.pptx"
PowerPointApp.ActivePresentation.Slides.Add i + 1, ppLayoutBlank
PowerPointApp.ActivePresentation.Slides(i + 1).Select
Table3.ChartObjects(i).CopyPicture
PowerPointApp.ActivePresentation.Slides(i + 1).Shapes.Paste
PowerPointApp.ActivePresentation.Slides(i + 1).Shapes(1).Top = 150
PowerPointApp.ActivePresentation.Slides(i + 1).Shapes(1).Left = 50
PowerPointApp.ActivePresentation.Slides(i + 1).Shapes(1).Width = 400
PowerPointApp.ActivePresentation.Slides(i + 1).Shapes(1).Height = 300
'Exception occurs here
PowerPointApp.ActivePresentation.Slides(i + 1).Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=100, Top:=100, Width:=200, Height:=50).TextFrame.TextRange.Text = "Text"
Next i