Please help!!! Wild Cards!! I didn't get replies, hence posing aga

V

vvskpk

Hi there,

I am using PPT 2007. I am want to use WildCards function for finding and
replacing a string.

My problem is, many ppt decks I will get will have phone numbers as
(xxx)-xxx-xxxx.

I want to replace all those formats to +1 xxx xxx xxxx. For example:
(123)-456-789 should become +1 123 456 789
(adding +1, removing brackets for first three digits, and replacing hyphens
with spaces)

In Word, I use Wild Cards while using Find and Replace option.
This is the command I use in Word:
Find What : \(([0-9]{3})\)-([0-9]{3})-([0-9]{4})
Replace With: +1 \1 \2 \3

But in PPT, I am unable to do the same function. I need to manually search
and replace each instance.

Please help in creating a macro using WildCard search or suggest any similar
find and replace option to do the above action.

Thanks in Advance!
 
J

John Wilson

As Steve says Reg Expressions is the way to go

You should use $1 $2 $3 not \1 \2 \3 I think

Sub Format_Phone()
Dim strFind As String
Dim osld As Slide
Dim oshp As Shape
Dim oTxtRng As TextRange
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame.HasText Then
Set oTxtRng = oshp.TextFrame.TextRange
strFind = oTxtRng.Text
oTxtRng.Text = RegExpSub(strFind)
End If
End If
Next oshp
Next osld
End Sub
'----------------------------------------
Function RegExpSub(ReplaceIn)
Dim Reg_Exp As Object
Set Reg_Exp = CreateObject("vbscript.regexp")
Reg_Exp.Pattern = "\(([0-9]{3})\)-([0-9]{3})-([0-9]{4})"
Reg_Exp.Global = True
RegExpSub = Reg_Exp.Replace(ReplaceIn, "+1 $1 $2 $3")
End Function
 
M

Mark

For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes

If your text could be in the Master/Layout slides, you will want to
look for shapes there as well.

Also, you need to check for tables or groups, as these need to be
processed further.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top