[英]Is there a direct way to get the index of a slide in a PowerPoint presentation?
我試圖以編程方式復制PowerPoint演示文稿中的幻燈片,並將其粘貼到原始文件后。
我的第一個想法是獲取舊幻燈片的索引,並將副本添加到所需的新索引,但我似乎無法找到一種直接的方法來檢索該索引。 我希望有類似Slides.IndexOf(Slide slide)
東西,但找不到那樣的東西。 我最后編寫了非常老派的代碼,這似乎有用,但我很好奇是否有更好的方法來做到這一點。
var slide = (PowerPoint.Slide)powerpoint.ActiveWindow.View.Slide;
var slideIndex = 0;
for (int index = 1; index <= presentation.Slides.Count; index++)
{
if (presentation.Slides[index] == slide)
{
slideIndex = index;
break;
}
}
這是C#/ VSTO,但任何可以讓我走上正確道路的輸入都值得贊賞,無論是VBA還是VB!
是的,你想要的是Duplicate
,它返回一個SlideRange
。 這是VBA中的一個例子:
Sub DuplicateSlide()
Dim ap As Presentation
Set ap = ActivePresentation
Dim sl As SlideRange
Set sl = ap.Slides(2).Duplicate
End Sub
要獲得幻燈片的索引,您可以使用:
Sub GetSlideIndex()
Dim ap As Presentation
Set ap = ActivePresentation
Set sl = ap.Slides(2)
Debug.Print sl.SlideIndex
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.