vba powerpoint 按名称选择幻灯片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25038952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
vba powerpoint select a slide by name
提问by user1813251
I am trying to select a slide by name. I have added a title via the outline. below is the code that is not working. "item Idaho not found in the slide collection"
我正在尝试按名称选择幻灯片。我通过大纲添加了一个标题。下面是不起作用的代码。“在幻灯片集合中找不到项目爱达荷州”
ActivePresentation.Slides("Idaho").Select
回答by Steve Rindsberg
The slide's name and the text in the title placeholder nave nothing to do with one another.
幻灯片的名称和标题占位符中的文本彼此无关。
Unless you've renamed it, the first slide in the presentation will be named "Slide1", the second "Slide2" and so on.
除非您已重命名,否则演示文稿中的第一张幻灯片将命名为“Slide1”,第二张为“Slide2”,依此类推。
If you specifically need a way to locate the slide whose title text = "Idaho", you'd need to write a function to search all the slides in the presentation and return the first one it finds that meets your criteria. For example:
如果您特别需要一种方法来定位标题文本 = "Idaho" 的幻灯片,您需要编写一个函数来搜索演示文稿中的所有幻灯片并返回它找到的第一个符合您条件的幻灯片。例如:
Sub TestMe()
Dim oSl As Slide
Set oSl = FindSlideByTitle("idaho")
If Not oSl Is Nothing Then
MsgBox "Found your title on slide " & CStr(oSl.SlideIndex)
End If
End Sub
Function FindSlideByTitle(sTextToFind As String) As Slide
Dim oSl As Slide
For Each oSl In ActivePresentation.Slides
With oSl.Shapes.Title.TextFrame
If .HasText Then
If UCase(.TextRange.Text) = UCase(sTextToFind) Then
Set FindSlideByTitle = oSl
End If
End If
End With
Next
End Function
回答by FreeMan
Reviving an old question, but I wanted to throw this in.
重温一个老问题,但我想把它扔进去。
While it's possible that ActivePresentation.Slides("MySlideName").Select
doesn't work, this does work for me in PPT 2010:
虽然这可能ActivePresentation.Slides("MySlideName").Select
不起作用,但这在 PPT 2010 中对我有用:
Dim PPTObj As PowerPoint.Application
Set PPTObj = New PowerPoint.Application
Dim PPTClinic As PowerPoint.Presentation
Set PPTClinic = PPTObj.Presentations.Open(FileName:="Your File Name Here")
PPTClinic.Slides("MySlideName").Select
This, of course, assumes that there is a slide named "MySlideName". Your code will have to deal with gracefully handling the Item MySlideName not found in the Slides collection.
error (err.number = -2147188160
).
当然,这假设有一张名为“MySlideName”的幻灯片。您的代码将不得不优雅地处理Item MySlideName not found in the Slides collection.
错误 ( err.number = -2147188160
)。