Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
 
Posts: n/a
Default Find & Replace &vba: formatting, like bold

I need a macro that searches for telephone numbers and replaces them
with same number + format = bold. How? Recording a macro for this does
not work: the recorded macro only deletes the telephone numbers =).

So I search for one of these:
^#^#^# ^#^#^#^#
^#^#^# ^#^#^# ^#^#^#^#
^#^#^#^ #^#^# ^#^#^#^

  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Suzanne S. Barnhill
 
Posts: n/a
Default Find & Replace &vba: formatting, like bold

Are you using ^& as the "Replace with" text?

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

wrote in message
oups.com...
I need a macro that searches for telephone numbers and replaces them
with same number + format = bold. How? Recording a macro for this does
not work: the recorded macro only deletes the telephone numbers =).

So I search for one of these:
^#^#^# ^#^#^#^#
^#^#^# ^#^#^# ^#^#^#^#
^#^#^#^ #^#^# ^#^#^#^


  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor
 
Posts: n/a
Default Find & Replace &vba: formatting, like bold

Unfortunately the macro recorder will not add the bold attribute. You will
have to add it to the macro
Given that the posted strings are not viable search strings (well the third
one isn't - I have changed it to 000 000 0000) the following macro will
work:

Sub ReplaceList()
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long

vFindText = Array("^#^#^# ^#^#^#^#", _
"^#^#^# ^#^#^# ^#^#^#^#", _
"^#^#^# #^#^# ^#^#^#^#")
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = True

For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = "^&"
.Replacement.Font.Bold = True
.Execute replace:=wdReplaceAll
Next i
End With
End Sub

Suzanne S. Barnhill wrote:
Are you using ^& as the "Replace with" text?


wrote in message
oups.com...
I need a macro that searches for telephone numbers and replaces them
with same number + format = bold. How? Recording a macro for this
does not work: the recorded macro only deletes the telephone numbers
=).

So I search for one of these:
^#^#^# ^#^#^#^#
^#^#^# ^#^#^# ^#^#^#^#
^#^#^#^ #^#^# ^#^#^#^



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
 
Posts: n/a
Default Find & Replace &vba: formatting, like bold

Excellent, works!

How should I modify this macro so that it is not applied to whole
document? I would like it to be applied to only selected text.

  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Tony Jollans
 
Posts: n/a
Default Find & Replace &vba: formatting, like bold

1. Remove this line (which makes it start at the beginning of the document):

Selection.HomeKey Unit:=wdStory

2. Change this line (which amkes it loop when it's done the selection):

.Wrap = wdFindContinue

To this (which makes it stop when it's done the selection):

.Wrap = wdFindStop

--
Enjoy,
Tony

wrote in message
oups.com...
Excellent, works!

How should I modify this macro so that it is not applied to whole
document? I would like it to be applied to only selected text.



Reply
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
Using find and replace or macros to replace page ranges JeremyC Microsoft Word Help 7 February 13th 06 09:20 PM
Find and Replace GREEK symbols in XP, 2K & 97 Jazz Microsoft Word Help 3 April 8th 05 08:13 PM
Find (NO formatting) not finding word that IS there. Ann Brownell Microsoft Word Help 0 March 24th 05 10:29 PM
Replace Formatting With Tags Bob Beveridge Microsoft Word Help 3 February 2nd 05 03:15 PM
Find Replace bold formatting with delimiter Steve Microsoft Word Help 7 December 7th 04 03:41 PM


All times are GMT +1. The time now is 05:32 PM.

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

About Us

"It's about Microsoft Word"