Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace followup
Hi everybody,
I got my macro recorded so I can replace my text, but for some reason, when I run it, it does nothing. I know Microsoft Word has some weird bugs in it that doesn't always show paragraph and font formatting when you replace, so I tried to fix it and it doesn't look like I was sucessful. Anyway, can anyone tell me where I need to fix this macro? Thanks again! Jezzica85 Sub Tagger() ' Replace centered, otherwise unformatted text with itself, surrounded by [C] tags, bolded Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphCenter End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[C]^&[/C]" .Replacement.Font.Bold = True .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace centered italicized text with itself, surrounded by [CI] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphCenter End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[CI]^&[/CI]" .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace left aligned italicized text with itself, surrounded by [LI] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphLeft End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[LI]^&[/LI]" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace left aligned, otherwise unformatted text with itself, surrounded by [L] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphLeft End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[L]^&[/L]" .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll End Sub |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace followup
It helps if you stick to the same thread for the same problem!
Your macro does nothing because it searches for nothing and replaces with something. The macro recorder is not capable of recording all actions and recording formatting is one of the things it cannot do. An example of a macro to find formatted text (and replace witha text string) is shown below. I have inserted the alternative lines so you can experiment. Note that the tags may not go where you might expect. Sub ReplaceExample() Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find '********************** .Text = "" .Font.Italic = True '.Font.Italic = False .ParagraphFormat.Alignment = wdAlignParagraphLeft '.ParagraphFormat.Alignment=wdAlignParagraphCenter .Replacement.Text = "[LI]^&[\LI]" '********************** .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False End With Selection.Find.Execute replace:=wdReplaceAll End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org jezzica85 wrote: Hi everybody, I got my macro recorded so I can replace my text, but for some reason, when I run it, it does nothing. I know Microsoft Word has some weird bugs in it that doesn't always show paragraph and font formatting when you replace, so I tried to fix it and it doesn't look like I was sucessful. Anyway, can anyone tell me where I need to fix this macro? Thanks again! Jezzica85 Sub Tagger() ' Replace centered, otherwise unformatted text with itself, surrounded by [C] tags, bolded Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphCenter End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[C]^&[/C]" .Replacement.Font.Bold = True .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace centered italicized text with itself, surrounded by [CI] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphCenter End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[CI]^&[/CI]" .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace left aligned italicized text with itself, surrounded by [LI] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphLeft End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[LI]^&[/LI]" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace left aligned, otherwise unformatted text with itself, surrounded by [L] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphLeft End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[L]^&[/L]" .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll End Sub |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace followup
Oh, and one thing I forgot to add--I think it's all sort of the same problem
in each of the four different sections. "jezzica85" wrote: Hi everybody, I got my macro recorded so I can replace my text, but for some reason, when I run it, it does nothing. I know Microsoft Word has some weird bugs in it that doesn't always show paragraph and font formatting when you replace, so I tried to fix it and it doesn't look like I was sucessful. Anyway, can anyone tell me where I need to fix this macro? Thanks again! Jezzica85 Sub Tagger() ' Replace centered, otherwise unformatted text with itself, surrounded by [C] tags, bolded Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphCenter End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[C]^&[/C]" .Replacement.Font.Bold = True .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace centered italicized text with itself, surrounded by [CI] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphCenter End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[CI]^&[/CI]" .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace left aligned italicized text with itself, surrounded by [LI] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphLeft End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[LI]^&[/LI]" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace left aligned, otherwise unformatted text with itself, surrounded by [L] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphLeft End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[L]^&[/L]" .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll End Sub |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Find and replace followup
Thank you for the hint Graham, I figured this out now. I'll remember that
same thread thing in the future. Jezzica85 "Graham Mayor" wrote: It helps if you stick to the same thread for the same problem! Your macro does nothing because it searches for nothing and replaces with something. The macro recorder is not capable of recording all actions and recording formatting is one of the things it cannot do. An example of a macro to find formatted text (and replace witha text string) is shown below. I have inserted the alternative lines so you can experiment. Note that the tags may not go where you might expect. Sub ReplaceExample() Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find '********************** .Text = "" .Font.Italic = True '.Font.Italic = False .ParagraphFormat.Alignment = wdAlignParagraphLeft '.ParagraphFormat.Alignment=wdAlignParagraphCenter .Replacement.Text = "[LI]^&[\LI]" '********************** .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = False End With Selection.Find.Execute replace:=wdReplaceAll End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org jezzica85 wrote: Hi everybody, I got my macro recorded so I can replace my text, but for some reason, when I run it, it does nothing. I know Microsoft Word has some weird bugs in it that doesn't always show paragraph and font formatting when you replace, so I tried to fix it and it doesn't look like I was sucessful. Anyway, can anyone tell me where I need to fix this macro? Thanks again! Jezzica85 Sub Tagger() ' Replace centered, otherwise unformatted text with itself, surrounded by [C] tags, bolded Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphCenter End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[C]^&[/C]" .Replacement.Font.Bold = True .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace centered italicized text with itself, surrounded by [CI] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphCenter End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[CI]^&[/CI]" .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace left aligned italicized text with itself, surrounded by [LI] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphLeft End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[LI]^&[/LI]" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False End With Selection.Find.Execute Replace:=wdReplaceAll ' Replace left aligned, otherwise unformatted text with itself, surrounded by [L] tags Selection.Find.ClearFormatting With Selection.Find.ParagraphFormat .Alignment = wdAlignParagraphLeft End With Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "[L]^&[/L]" .Forward = True .Wrap = wdFindContinue .Format = True End With Selection.Find.Execute Replace:=wdReplaceAll End Sub |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Find multiple characters in one find using MSword find/replace | Microsoft Word Help | |||
Trying to replace words with fields using Find/Replace | Microsoft Word Help | |||
Using find and replace or macros to replace page ranges | Microsoft Word Help | |||
Find/ Replace is auto-capping the words I want to replace with | Microsoft Word Help | |||
Find and Replace: delete a line & find a number 10 | Microsoft Word Help |