我試圖從Excel(VBA)創建一個powerpoint(包含模板)並向每張幻燈片添加一個文本框。從Excel創建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語句'開頭的地方)。在模板或代碼的其他代碼段中可能存在某種外部特徵。但我不這麼認爲... –
運行時錯誤'-2147024809(80070057)' 出境異常 對不起 - 我忘了刪除聲明結束。 – red