Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Pleonasm
 
Posts: n/a
Default Macro: Execute for Selected Text Only

I am seeking to execute the following Microsoft Word 2003 find/replace macro
(Windows XP Pro SP2) €“ but only for a block of text that has been selected.
At present, the macro executes upon the entire document. How can I constrain
its execution to only selected text?

Thank you for your assistance.

Sub Macro()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13 {1,}"
.Replacement.Text = "^13"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Ed
 
Posts: n/a
Default Macro: Execute for Selected Text Only

Try this: Just after Sub Macro(), add the following lines:
Dim myRange as Range
Set myRange = Selection.Range

Then, is every line of your macro, replace "Selection" with "myRange"
(without any quote marks).

Give that a shot and see if it works for you.

Ed

"Pleonasm" wrote in message
...
I am seeking to execute the following Microsoft Word 2003 find/replace

macro
(Windows XP Pro SP2) - but only for a block of text that has been

selected.
At present, the macro executes upon the entire document. How can I

constrain
its execution to only selected text?

Thank you for your assistance.

Sub Macro()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13 {1,}"
.Replacement.Text = "^13"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Tony Jollans
 
Posts: n/a
Default Macro: Execute for Selected Text Only

Change ...

..Wrap = wdFindContinue

to ...

..Wrap = wdFindStop

--
Enjoy,
Tony


"Pleonasm" wrote in message
...
I am seeking to execute the following Microsoft Word 2003 find/replace

macro
(Windows XP Pro SP2) - but only for a block of text that has been

selected.
At present, the macro executes upon the entire document. How can I

constrain
its execution to only selected text?

Thank you for your assistance.

Sub Macro()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13 {1,}"
.Replacement.Text = "^13"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub



  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Pleonasm
 
Posts: n/a
Default Macro: Execute for Selected Text Only

Tony, your recommendation worked well.

Thanks for the advice.
  #5   Report Post  
Posted to microsoft.public.word.docmanagement
Tony Jollans
 
Posts: n/a
Default Macro: Execute for Selected Text Only

My pleasure!

--
Enjoy,
Tony


"Pleonasm" wrote in message
...
Tony, your recommendation worked well.

Thanks for the advice.



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
Creating dynamic cross reference links in a Word document torajudo Microsoft Word Help 5 April 27th 23 08:57 PM
Word applies direct format on File open Uriel Microsoft Word Help 16 November 27th 05 07:22 PM
Macro doesn't work Anna Microsoft Word Help 9 October 17th 05 10:25 PM
How can I make a shortcut or macro to paste text only format? ray Microsoft Word Help 3 October 8th 05 02:15 AM
Macro for bold text using wildcard Suusje Microsoft Word Help 0 September 26th 05 03:50 PM


All times are GMT +1. The time now is 06:49 AM.

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"