Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF

Substitute one string for another in text

Sub TheCatInTheHat()

Dim oTextRange As TextRange
Dim OriginalString As String
Dim NewString As String
Dim FindThis As String ' what string are we looking for?
Dim SubstituteThat As String ' what do we replace it with

FindThis = "XXXXXX"
SubstituteThat = "yada yada yada"

' Get a reference to the text you want to manipulate:
' I'm just grabbing the current selection
' You'd want to do this differently
Set oTextRange = ActiveWindow.Selection.ShapeRange.TextFrame.TextRange
OriginalString = oTextRange.Text

' Is the target string part of the text? If not, bug out.
If InStr(OriginalString, FindThis) = 0 Then
Exit Sub
End If

' Get the portion of the string up to but not including where FindThis starts
NewString = Mid$(OriginalString, 1, InStr(OriginalString, FindThis) - 1)

' Add the substitute string
NewString = NewString & SubstituteThat

' Add the portion of the original string after but not including FindThis
NewString = NewString & Mid$(OriginalString, InStr(OriginalString, FindThis) + Len(FindThis))

' Uncomment this, comment out the next if you want to see the result w/o changing the original
'MsgBox NewString

oTextRange.Text = NewString

End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2015 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.
Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Substitute one string for another in text
http://www.pptfaq.com/FAQ00379_Substitute_one_string_for_another_in_text.htm
Last update 07 June, 2011
Created: