How to search and replace certain format

J

Jan Kratochvil

I have style Normal with some special formating and I need to replacet this
text with other style.

But I can't find this formated text.
This Normal style has bullets (Font Name Symbol code 215).

I don't know how to find and raplace it in whole document with a new style
with bullets.

I need to have all paragraps with the same bullets styles.
 
K

Klaus Linke

Jan Kratochvil said:
I have style Normal with some special formating and I need to replace this
text with other style.

But I can't find this formated text.
This Normal style has bullets (Font Name Symbol code 215).

I don't know how to find and raplace it in whole document with a new style
with bullets.

I need to have all paragraps with the same bullets styles.


Hi Jan,

Since there are a lot of ways to do bullets and numbering, maybe try a
method that works with any formatting first:

Make sure that "Office Button > Word options > Advanced > Keep track of
formatting" is checked.
(Hope I translated that ok from the German version)

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.

If this method works, you could write a macro that does the same thing. Post
back if that is the case, and you need help with it. The part that selects
similar formatting is:
WordBasic.SelectSimilarFormatting


If it doesn't, you might have to loop all paragraphs and check for the
particular bullet. If it's autonumbering, you could go through all
paragraphs with the particular list template, or look out for the specific
bullet:

Debug.Print AscW(Selection.Range.ListFormat.ListString)
(... should be 215 in your case)

Debug.Print Selection.Range.ListFormat.ListTemplate.ListLevels(1).Font.Name
(... should be "Symbol" in your case)

Regards,
Klaus
 
J

Jan Kratochvil

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
 
K

Klaus Linke

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
 
J

Jan Kratochvil

Hi Klaus

I send you a link with this style - You will understand easier what type of
text I am searching for.

Here is the link: www.vranov-podyji.cz/temp/lorem.zip
There is only one style inside.
This is the style what I am looking for.

I don't now how to write the right conditional statement for searching and
replacing this text.

I will look Your code below.

Thank you for Your time - Jan
I am using W2007.
 
J

Jan Kratochvil

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
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Klaus Linke

The solution I proposed first seems to work just fine.
If I go into one of the Normal style paragraphs with bullets, and "select
all 2 instances", I can then appy a bullet style (odrazka-popis-pole or some
other style).

If you want to find all paragraphs with this bullet, no matter what style is
applied, you can use something like the two code samples I gave in my first
reply, say like this:

Dim myPara As Paragraph
For Each myPara In ActiveDocument.Paragraphs
If myPara.Range.ListFormat.ListString <> "" Then
If Hex(AscW(myPara.Range.ListFormat.ListString)) = "F0D7" Then
If Selection.Range.ListFormat.ListTemplate.ListLevels(1).Font.Name =
"Symbol" Then
' next two lines just for debugging:
myPara.SelectNumber
MsgBox "Here:"

myPara.Style = ActiveDocument.Styles(wdStyleListBullet)
' ... or apply some other of your styles
End If
End If
End If
Next myPara
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

The "bold" is then applied on top of the style as manual formatting...
something that should be avoided.
An occasional bold or italic word is ok, but applying some manual formatting
to the whole document or a whole paragraph isn't usually a good idea.
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.

The docs almost certainly contain lots of manual formatting. Sometimes it's
best to remove all manual paragraph formatting (ResetPara = Ctrl+Q) and font
formatting (Ctrl+Spacebar), and then apply proper paragraph (and possibly
character, list and table) styles.
Or in newer versions of Word, you can use the "styles and formatting" pane.
Turn on "Keep track of formatting" (Tools > Options > Edit), and you see all
the types of manual formatting that have been applied (... visible in the
pane by the missing symbol, ¶ or ª). Use "Select all # instances" again, and
apply a proper style.

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top