【发布时间】:2013-08-29 17:33:06
【问题描述】:
我正在尝试从 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
【问题讨论】:
-
什么是异常编号和描述?
-
更多——在我关闭一些本地设置(如模板)后,你的代码对我来说运行良好。但是您向我们展示的是不完整的代码(例如,
With statement的开头在哪里)。模板或代码的其他 sn-p 中可能有一些东西。但我不这么认为...... -
RunTime Error '-2147024809 (80070057)' Out of bounds exception 抱歉 - 我忘了删除 end with 语句。
-
太棒了!在英语中是...?
-
尝试将问题行中的这个:
msoTextOrientationHorizontal更改为1(是的,单个数字 = 1)
标签: excel vba powerpoint