Re: How to search and replace certain format

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Maybe this will help? It will allow you to pick a style from those available
and replace it with another picked from those available.


Sub ReplaceStyle()
Dim FindStyle As String
Dim ReplaceStyle As String

FindInput:
MsgBox "Pick style to find", vbInformation, "Find Style"
With Dialogs(wdDialogFormatStyle)
.Display
FindStyle = .Name
End With

ReplaceInput:
MsgBox "Replace " & FindStyle & " style with which style?", _
vbInformation, "Replace Style"
With Dialogs(wdDialogFormatStyle)
.Display
ReplaceStyle = .Name
End With
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
On Error GoTo FindError
Selection.Find.Style = ActiveDocument.Styles(FindStyle)
Selection.Find.Replacement.ClearFormatting
On Error GoTo ReplaceError
Selection.Find.Replacement.Style = _
ActiveDocument.Styles(ReplaceStyle)
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles(ReplaceStyle)
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = _
ActiveDocument.Styles("Default Paragraph Font")
With Selection.Find
.Text = ""
.Replacement.Text = ""
End With
Selection.Find.Execute replace:=wdReplaceAll
End
FindError:
MsgBox Prompt:=FindStyle & " Style does not exist", _
Buttons:=vbExclamation, _
Title:="Error!"
GoTo FindInput
ReplaceError:
MsgBox Prompt:=ReplaceStyle & " Style does not exist", _
Buttons:=vbExclamation, _
Title:="Error!"
GoTo ReplaceInput
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Jan Kratochvil wrote:
I found one Problem by searching the defined styles.

Please look the file:
http://vranov-podyji.cz/temp/lorem-2styles.zip

There is 2 styles:
Normal
odrazka-popis-pole

I don't know how to find the style with name "odrazka-popis-pole"

I need to join the text with styles "odrazka-popis-pole" and
"Normal"(with bullet) -> into the same style e.g. Bullets or some my
style
-----

Mystery for me still is how Word deal with styles.

If I have style Normal and select this text and press Crtl+B - is it
still style Normal, but BOLD

I don't know than how to hold the same look of the text.
Mostly is it problem if I get the document from someone else than is
very hard to make a new formating.
I mean e.g. select text with Normal style - the Normal text looks
different - sometime is bold, sometime italic, but still Normal style.

Can somebody explane me how it works exactly?

Thanks


"Klaus Linke" <info@xxxxxxxxxxxxxxxxxxxx> pí¹e v diskusním pøíspìvku
news:ubXa%23Td2HHA.5992@xxxxxxxxxxxxxxxxxxxxxxx
Hi Jan,

Are the bullets typed in, or are they autonumbering?
I assumed the latter, but since the method I suggested selects too
much, it seems the bullets are hard text.


In that case, you can use Edit>Replace:

You didn't mention what version you use. If it isn't Word 2000, you
can copy the bullet into the "Find" dialog (Ctrl+C, Ctrl+V), and
specify the font (More > Format > Font).
In "Replace with", you can specify your bullet style (... insert its
name for "YourListStyle" below).

Record that, and you get something like

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Font.Name = "Symbol"
Selection.Find.Replacement.Style =
ActiveDocument.Styles("YourListStyle") With Selection.Find
.Text = ChrW(61655)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

The macro recorder sometimes doesn't record everything, or adds
stuff, so I had to edit the code of the macro recorder a bit.

You now still have the bullets and the whitespace after them which
you probably want to delete.
You can do that with another replacement:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("YourListStyle")
With Selection.Find
.Text = ChrW(61655) & "^w"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Hope it works,
Klaus



"Jan Kratochvil" <snah@xxxxxxxxx> wrote:
Thank you for answer Klaus, but I can't use this method :

Then display the "Styles and formatting" task pane
(Alt+Ctrl+Shift+S). Put the cursor in one of the bulletted
paragraphs. With the right mouse button, click on the selected item in
the
pane, and choose "Select all # instances".
Now, if all the paragraphs you want to change are selected, you can
apply another paragraph style to them.

The reason is, that the selections select nearly all text of my
document because the text with bullets is in Normal style also.

I tried to use this code, but I don't know how can I find and
replace my formated text and replace with the same List.

Thanks Jan


.



Relevant Pages

  • Re: How to search and replace certain format
    ... Are the bullets typed in, ... font (More> Format> Font). ... .MatchWholeWord = False ... I had to edit the code of the macro recorder a bit. ...
    (microsoft.public.word.vba.beginners)
  • Re: How to search and replace certain format
    ... different - sometime is bold, sometime italic, but still Normal style. ... Are the bullets typed in, ... font (More> Format> Font). ... .MatchWholeWord = False ...
    (microsoft.public.word.vba.beginners)
  • Re: How to search and replace certain format
    ... Are the bullets typed in, ... (More> Format> Font). ... .MatchWholeWord = False ... The macro recorder sometimes doesn't record everything, or adds stuff, so I ...
    (microsoft.public.word.vba.beginners)
  • RE: Font Change in Word Macro
    ... .Wrap = wdFindAsk ... .Format = False ... .MatchWholeWord = False ... .Wrap = wdFindContinue ...
    (microsoft.public.word.vba.general)
  • Word Macro to Clean Up SQL
    ... .Format = False ... .MatchWholeWord = False ... .MatchSoundsLike = False ... .MatchAllWordForms = False ...
    (microsoft.public.access.queries)