0

I need to find and replace a string in PPT. But the length of the string will vary and PPT does not allow wildcard searches like Word. I need to find every string that begins with <REF and end with >. In Word I would search for <REF*>. How do I do this in PPT? Here is what I have so far, but this only finds some of the strings. Please help!

Function FindAndReplace(s As String, replacementText As String) As String
  Const LEFT As String = "<REF"
  Const RIGHT As String = ">"
  Dim temp As String
  temp = s
  Dim iPos As Integer
  iPos = 1
  Dim iStart As Integer, iEnd As Integer
  Do
    iPos = InStr(iPos, temp, LEFT)
    If iPos = 0 Then
      FindAndReplace = temp
      Exit Function
    End If

    iStart = iPos
    iEnd = InStr(iStart, temp, RIGHT)
    If iEnd = 0 Then
      FindAndReplace = temp
      Exit Function
    End If

    Dim targetText As String
    iEnd = iEnd + 1
    targetText = Mid(temp, iStart, iEnd - iStart)
    temp = Replace(temp, targetText, replacementText)
    iPos = iPos + Len(LEFT) + Len(targetText) + Len(RIGHT)
If iPos >= Len(temp) Then Exit Do
  Loop
  FindAndReplace = temp
End Function
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • 1
    Have you considered [regular expressions](https://stackoverflow.com/questions/22542834/how-to-use-regular-expressions-regex-in-microsoft-excel-both-in-cell-and-loops)? – Comintern Feb 26 '19 at 20:29
  • Getting all the text from ppt may be a uphill task. Here is good [reading](http://www.pptfaq.com/FAQ00274_Export_Text_to_a_text_file-_extract_text_from_PowerPoint_-Mac_or_PC-.htm). Even the example does not cover all the type of shapes that may conatain text. – Ahmed AU Feb 27 '19 at 00:22

0 Answers0