Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
jezzica85 jezzica85 is offline
external usenet poster
 
Posts: 71
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
jezzica85 jezzica85 is offline
external usenet poster
 
Posts: 71
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
jezzica85 jezzica85 is offline
external usenet poster
 
Posts: 71
Default 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

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 multiple characters in one find using MSword find/replace Cliff Microsoft Word Help 2 October 29th 06 07:48 PM
Trying to replace words with fields using Find/Replace mbleyle Microsoft Word Help 2 March 29th 06 11:35 PM
Using find and replace or macros to replace page ranges JeremyC Microsoft Word Help 7 February 13th 06 09:20 PM
Find/ Replace is auto-capping the words I want to replace with Graham Mayor Microsoft Word Help 8 January 27th 06 01:39 AM
Find and Replace: delete a line & find a number 10 Janis Anna Microsoft Word Help 3 October 23rd 05 05:53 AM


All times are GMT +1. The time now is 04:42 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"