I have been trying to find a way to identify a placeholder on a PowerPoint slide using the placeholder name and then read the text contents of the place
holder. It seems like the FindByName method should work for this but so far all attempts to use it result in a
“Placeholders (unknown Member): Object does not exist” error at Line #22.
Specifically, I am trying to:
1.
Find the place holder named LessonIdentifier on any sheet with the
ppLayoutSectionHeader layout
2.
Extract the text in that placeholder and use it for further processing.
My code looks like this
01
Sub AddLessonIdentifier()
02
Dim sl As Slide
03
Dim sh As Shape
04
Dim titleText As String
05
Dim LessonTitle As String
06
Dim LessonFlag As Boolean
07
Dim PH As Shape
08
09
LessonTitle = ""
10
LessonFlag = False
11
pagecount = PowerPoint.ActivePresentation.Slides.Count
12
13
'loop through all of the slides
14
For Each sl In PowerPoint.ActivePresentation.Slides
15
sl.Select
16
PageNo = sl.SlideNumber
17
titleText = ""
18
titleText = sl.Shapes.Title.TextFrame.TextRange.Text
19
On Error Resume Next 'Used to prevent an error at #22
20
' If the slide layout is Section Header, find the placeholder named "LessonPlaceholder"
21
If sl.Layout = ppLayoutSectionHeader Then
22
Set PH = sl.Shapes.Placeholders.FindByName("LessonPlaceholder")
23
LPHText = PH.TextFrame.TextRange.Text
24
If IsEmpty(LPHText) Then LPHText = "Empty"
25
Debug.Print "LPHText: "
26
Debug.Print LPHText
27
End If
28
29
'Get the count of placeholders on the slide, loop through all a printing selected properties
30
PHCount = sl.Shapes.Placeholders.Count
31
Debug.Print "Placeholder Count: " & PHCount
32
Debug.Print "Slide", "Index", "Name", "Text"
33
For Each PH In sl.Shapes.Placeholders
34
PlaceHolderText = PH.TextFrame.TextRange.Text
35
PlaceHolderIndex = PH.Id
36
PlaceHolderName = PH.Name
37
Debug.Print PageNo, PlaceHolderIndex, PlaceHolderName, PlaceHolderText
38
Next PH
39
40
On Error GoTo 0
41
.
42
.
43
.
44
<other actions>
45
46
47
Next sl
48
49
End Sub
If I remove the
On Error Resume Next at #19 then I get a
“Placeholders (unknown Member): Object does not exist” error at #22.
Otherwise, the relevant output for slide 14 (the first with the Section Header, layout) looks like this:
LPHText:
Empty
Placeholder Count: 2
Slide
Index Name Text
14
2 Title Welcome to SSIS
14
5 LessonPlaceholder
Lesson 1
It clearly shows that there is a Placeholder on the slide, that is named “LessonPlaceholder”. I'm completely baffled.