Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
vvskpk vvskpk is offline
external usenet poster
 
Posts: 5
Default Find and Replace any digit

Find and Replace any digit

I am posting this again hoping that earlier thread is not active/went
behind. You can reply if the earlier thread is active. Very Sorry for
occupying the space.

Everyone!
Thanks for your kind suggestions. BUT I am sorry to say that it's not
working. I tried putting this in the Find and Replace but is not working. In
Find What I typed/copied "\(([0-9]{3})\)-([0-9]{3})-([0-9]{4})" and in
Replace with I typed "+1 \1 \2 \3". It is giving me error saying "Word has
finished searching the document. The search item was not found".

New viewers!
I need a tag to findout the format (000)-000-0000 and replace with +1 000
000 0000 (+1 prefix and no dashes). This is to replace all phone number
format in a big number of document(s). I am using Vista and Office 2007.
Please check the thread "Find and Replace any digit" and the vaulable
suggestions given by experts, but may be something is missing in that.

Please understand and help me! Really appreacite your authenticity,
knowledge, experience and transparency in sharing about the subject.

_________________

"Greg Maxey" wrote:

I guess you meant to say "carry", not "care"

You may often wonder, but never know. It could have been intentional and
fodder for my critics. ;-)

Doug Robbins - Word MVP wrote:
I guess you meant to say "carry", not "care"



G, D & R V,V,F

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Greg Maxey" wrote in
message ...
Considering your thoroughness, I think you should be absolved of the
crime of expressing yourself poorly. You should not have to care
that heavy burden of guilt.
Do you think it would do any good to petition an appeal from the self
appointed newsgroup courtesy and expression quality policeman?

Graham Mayor wrote:
I missed it too until I tested the macro and saw the result


Greg Maxey wrote:
Graham,

Well said. Perfectly expressed. I missed the part on omiting the
dashes.
Graham Mayor wrote:
It should be
\(([0-9]{3})\)-([0-9]{3})-([0-9]{4})
replace with
+1 \1 \2 \3
if you want to remove the dashes also.
http://www.gmayor.com/replace_using_wildcards.htm

You can paste these strings to the dialog boxes in the following
batch process to search all the documents in a folder
http://www.gmayor.com/installing_macro.htm

Public Sub BatchReplaceAnywhere()
'Macro by Doug Robbins - 1st March 2004
'with additional input from Peter Hewett
'and Graham Mayor 'to replace text in all the documents in a
folder Dim FirstLoop As Boolean
Dim myFile As String
Dim strPath As String
Dim myDoc As Document
Dim rngstory As Word.Range
Dim findText As String
Dim Replacement As String
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.title = "Select Folder containing the documents to be modifed
and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) "\" Then strPath = strPath + "\"
End With
'Close any documents that may be open
If Documents.Count 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
FirstLoop = True
myFile = Dir$(strPath & "*.doc")
While myFile ""
'Get the text to be replaced and the replacement
If FirstLoop = True Then
findText = InputBox("Enter the text that you want to
replace.", _ "Batch Replace Anywhere")
If findText = "" Then
MsgBox "Cancelled by User"
Exit Sub
End If
TryAgain:
Replacement = InputBox("Enter the replacement text.", _
"Batch ReplaceAnywhere ")
If Replacement = "" Then
Response = MsgBox("Do you just want to delete the found
text?", _
vbYesNoCancel)
If Response = vbNo Then
GoTo TryAgain
ElseIf Response = vbCancel Then
MsgBox "Cancelled by User."
Exit Sub
End If
End If
FirstLoop = False
End If
'Open each file and make the replacement
Set myDoc = Documents.Open(strPath & myFile)
' Fix the skipped blank Header/Footer problem
MakeHFValid
' Iterate through all story types in the current document
For Each rngstory In ActiveDocument.StoryRanges
' Iterate through all linked stories
Do
SearchAndReplaceInStory rngstory, _
findText, Replacement
' Get next linked story (if any)
Set rngstory = rngstory.NextStoryRange
Loop Until rngstory Is Nothing
Next
'Close the file, saving the changes.
myDoc.Close SaveChanges:=wdSaveChanges
myFile = Dir$()
Wend
End Sub

Public Sub SearchAndReplaceInStory(ByVal rngstory As Word.Range, _
ByVal strSearch As String, _
ByVal strReplace As String)
'This routine supplied by Peter Hewett
Do Until (rngstory Is Nothing)
With rngstory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = strSearch
.Replacement.Text = strReplace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Set rngstory = rngstory.NextStoryRange
Loop
End Sub

Public Sub MakeHFValid()
Dim lngJunk As Long
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryT ype
End Sub



Greg Maxey wrote:
Use wildcards. Find:

\(([0-9]{3})\)(-[0-9]{3}-[0-9]{4})

Replace with:

1-\1\2

vvskpk wrote:
I am working in Word 2007.

I am trying for a different find and replace option but I am not
getting what I want. Here is the scenario:

I have many documents in which the phone numbers are given as
(000)-000-0000. I want all the numbers to replace with +1
prefixed and without brackets and dashes, like this, +1 000 000
0000. Now, I am able to find the numbers using ^# (any digit) in
"Find
What" by entering(^#^#^#)-^#^#^#-^#^#^#^#.
But couldn't replace with the format I am looking for which is
+1 ^#^#^# ^#^#^# ^#^#^#^# (+1 prefixed and no dashes).
It is giving me error when I give in Replace With field.

I can still use Find What using the any digit option, but
manually need to retype, hence, it will be really great if
someone can give me the easiest way to use Replace command.
There are many documents with minimum 100 pages and with phone
numbers entered in different locations which I need to replace
with the format I required. Again, I am using Vista and Word
2007 Many thanks in advance!


vvskpk


 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace any digit vvskpk Microsoft Word Help 10 November 30th 09 02:27 AM
Find a double digit Steved Microsoft Word Help 2 June 3rd 08 02:59 AM
Two decimal digit not printing correctly when last digit is a zero Catherine Mailmerge 1 January 19th 07 04:36 AM
Find multiple characters in one find using MSword find/replace Cliff Microsoft Word Help 2 October 29th 06 07:48 PM
How to replace 'any digit' with the same text? Caz Microsoft Word Help 5 September 23rd 06 02:42 PM


All times are GMT +1. The time now is 04:13 AM.

Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"