Raybob
02-15-2022, 02:59 PM
Hi all, I am trying to search for the first instance of "Material" in my powerpoint slide titles, and add a carriage return after it. I have been trying to use the find and replace function, but it seems to be random about working. . Right now it replaces all the text in the slide titles with "Material" rather than inserting a carriage return. Any ideas?
Sub Addlinetotitle()
Dim sld As Slide
Set sld = ActivePresentation.Slides(1)
Dim shp As Shape
Dim strFindWhat As String: strFindWhat = "Material"
Dim strReplaceWhat As String: strReplaceWhat = "Material" & vbCr
Dim treReplaced As TextRange
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Replace(FindWhat :=strFindWhat, ReplaceWhat:=strReplaceWhat)
End If
End If
Next
Next sld
End Sub
Sub Addlinetotitle()
Dim sld As Slide
Set sld = ActivePresentation.Slides(1)
Dim shp As Shape
Dim strFindWhat As String: strFindWhat = "Material"
Dim strReplaceWhat As String: strReplaceWhat = "Material" & vbCr
Dim treReplaced As TextRange
For Each sld In ActivePresentation.Slides
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = ActivePresentation.Slides(1).Shapes(1).TextFrame.TextRange.Replace(FindWhat :=strFindWhat, ReplaceWhat:=strReplaceWhat)
End If
End If
Next
Next sld
End Sub