Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2007

Tip: Looking for answers? Try searching our database.

How to search and replace certain format

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jan Kratochvil - 07 Aug 2007 07:47 GMT
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.

Signature

Jan Kratochvil, Office 2007, Win XP Pro SP2

Klaus Linke - 08 Aug 2007 03:31 GMT
"Jan Kratochvil" <snah@seznam.cz> schrieb:
>I have style Normal with some special formating and I need to replace this
>text with other style.
[quoted text clipped - 6 lines]
>
> 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
Jan Kratochvil - 08 Aug 2007 09:00 GMT
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

> "Jan Kratochvil" <snah@seznam.cz> schrieb:
>>I have style Normal with some special formating and I need to replace this
[quoted text clipped - 43 lines]
> Regards,
> Klaus
Klaus Linke - 08 Aug 2007 16:58 GMT
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

> Thank you for answer Klaus, but I can't use this method :
>
[quoted text clipped - 12 lines]
>
> Thanks Jan
Jan Kratochvil - 13 Aug 2007 07:24 GMT
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.

> Hi Jan,
>
[quoted text clipped - 73 lines]
>>
>> Thanks Jan
Jan Kratochvil - 13 Aug 2007 08:04 GMT
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

Signature

Jan Kratochvil, Office 2007, Win XP Pro SP2

> Hi Jan,
>
[quoted text clipped - 73 lines]
>>
>> Thanks Jan
Russ - 13 Aug 2007 09:05 GMT
Jan,
Here are some good links to research:
<http://www.shaunakelly.com/word/styles/TipsOnStyles.html>
<http://www.word.mvps.org/FAQs/General/FindingSpecialCharacters.htm>
<http://office.microsoft.com/en-us/word/HA011876141033.aspx>
<http://www.google.com/search?&q=paragraph+character+style+format+ingroup:wo
rd>

> I found one Problem by searching the defined styles.
>
[quoted text clipped - 26 lines]
>
> Thanks

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Jan Kratochvil - 13 Aug 2007 14:57 GMT
Thank you very much.

I made the whole training about Word styles
Now I understand more how Word works with styles.

Very useful training - I recommend if for all users thay have stilll a
question about Word Styles - like me ;)

http://office.microsoft.com/training/Training.aspx?AssetID=RC011039261033&CTT=6&
Origin=RC011039261033


Signature

Jan Kratochvil, Office 2007, Win XP Pro SP2

> Jan,
> Here are some good links to research:
[quoted text clipped - 36 lines]
>>
>> Thanks
Graham Mayor - 13 Aug 2007 09:23 GMT
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

Signature

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

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

> I found one Problem by searching the defined styles.
>
[quoted text clipped - 105 lines]
>>>
>>> Thanks Jan
Klaus Linke - 13 Aug 2007 14:52 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.