Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Macro: Execute for Selected Text Only
Tony, your recommendation worked well.
Thanks for the advice. |
#5
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Creating dynamic cross reference links in a Word document | Microsoft Word Help | |||
Word applies direct format on File open | Microsoft Word Help | |||
Macro doesn't work | Microsoft Word Help | |||
How can I make a shortcut or macro to paste text only format? | Microsoft Word Help | |||
Macro for bold text using wildcard | Microsoft Word Help |