Reputation: 5
My PowerPoint slides has a text boxes that have default text in it, such as "Profile Description" and when you click on it, the words "Profile Description" disappear, so you can type in the profile.
I want to find that specific text box, the one that contains the default text "Profile Description", by looking at the contents of the box (I can't use title, as the title might be different depending which slide its on).
I can find many other properties of this text, by using Slide.TextFrame.TextRange, but I can't figure out how to get that default text.
Once I click in the box and type some text, then I can access the new value using Slide.TextFrame.TextRange.Text, but I need the default text. I've looked at a ton of documentation, but I guess I'm missing it somewhere. Please point me in the right direction. Thanks.
Upvotes: 0
Views: 1607
Reputation: 65
I've been trying to find a way to make this work with Tags
, but couldn't.
So instead, my solution has been to pre-check the CustomLayout
for the Placeholders and note the top x,y coordinates and what values they should have by default.
After, when the page has been generated, I review the shapes by x,y coordinate and if there's a match, substitute in the default value.
Upvotes: 1
Reputation: 2979
Is that text box created from a placeholder? If so, you'll need to look at the parent placeholder on the custom layout associated with the slide, which is not trivial due the differences in collections indexing between a slide and a layout and the fact that the Name property changes each time the slide is generated from the master. Example:
oSld.CustomLayout.Shapes.Placeholders(index).TextFrame2.TextRange.Text
Note that this will work for custom text placeholders but not for built-in placeholders where text on the custom layout is dynamically replaced by PowerPoint on the slide.
Example:
Slide Master / Layout / Title Placeholder : "Click to edit Master title style"
Slide Placeholder : "Click to add title"
You could get a reference to the shape on the layout by using tags. Tags are bits of invisible meta data that you can add to presentations, slides or shapes.
This is how you add a tag to a shape on a slide:
ActivePresentation.Slides(1).Shapes(1).Tags.Add myName, myValue
You then write a function to return a shape by its tag like this:
' *************************************************************************************
' Purpose : Returns a presentation, slide or shape by its tag from a collection of
' presentations, slides or shapes
' Author : Jamie Garroch of YOUpresent.co.uk
' Inputs : TagObject - collection type to be searched. Presentations, Slides or Shapes
' TagName - The tag name to search for (always upper case)
' TagValue - The tag value to search for
' Outputs : Returns a Presentation, Slide or Shape object if a match is found
' *************************************************************************************
Public Function GetByTag(TagObject, TagName As String, TagValue As String) As Object
On Error GoTo errhandler
Select Case True
Case TypeOf TagObject Is Presentations
Dim oPres As Presentation
For Each oPres In TagObject
If TagExists(oPres, TagName, TagValue, True) Then Set GetByTag = oPres: Exit Function
Next
Case TypeOf TagObject Is Slides
Dim oSld As Slide
For Each oSld In TagObject
If TagExists(oSld, TagName, TagValue, True) Then Set GetByTag = oSld: Exit Function
Next
Case TypeOf TagObject Is Shapes
Dim oShp As Shape
For Each oShp In TagObject
If TagExists(oShp, TagName, TagValue, True) Then Set GetByTag = oShp: Exit Function
Next
End Select
Exit Function
errhandler: DebugMsg "GetByTag Error : " & Err & " " & Err.Description End Function
Upvotes: 1