簡體   English   中英

在VBA powerpoint中如何將新幻燈片添加到空的演示文稿中

[英]in VBA powerpoint How to add a new slide to an empty presentation

我想在一個空的演示文稿中添加一張新幻燈片。 我正在努力布局。 我使用以下內容:

Set pptLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1)
Set sld = ActivePresentation.Slides.AddSlide(1, pptLayout)
sld.Design = ActivePresentation.Designs(1)

當我的演示文稿中已有幻燈片時,此代碼工作正常,但我沒有!

所以,我的問題是:如果我沒有預先存在的幻燈片來設置它的布局,我怎么能插入幻燈片? 我的意思是在代碼的第一行,我使用幻燈片1定義布局,以便在.AddSlide中使用它

你可以簡單地使用這樣的東西:

ActivePresentation.Slides.Add Index:=ActivePresentation.Slides.Count + 1, Layout:=ppLayoutCustom

有了這個, 你不必從其他地方獲得布局 ,你可以改變它,看看你在屏幕截圖上的其他一些可能性:

在此輸入圖像描述

OP代碼的變體對我有用

Dim appPPT As PowerPoint.Application
dim ppObj As PowerPoint.Presentation
dim slideObj As PowerPoint.Slide
dim pptLayout As CustomLayout

Set appPPT = New PowerPoint.Application
Set ppObj = appPPT.Presentations.Add
Set pptLayout = ppObj.Designs(1).SlideMaster.CustomLayouts(7)
Set slideObj = ppObj.Slides.AddSlide(1, pptLayout)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM