How to search for (and select) paragraphs with certain formatparameters

P

Paul

I posted this in another thread, but the thread title dealt with a
larger contextual problem, so it may go unnoticed.

In Word 2003, I want to search for, and select, all paragraphs that
conform to a list of attributes e.g. left indent of 0.53", hanging
indent at 0.26", etc.. From the "Find and Replace" panel, I chose
Format->Paragraph, and set the left indent to 0.53", etc.. Word did
not find any of the paragraphs conforming to these attributes, even
though they exist. Is there a way to search for (and select)
paragraphs based on formatting parameters?

I am using Word 2003.
 
S

Suzanne S. Barnhill

In this case the indent is set in the Bullets (Numbering) dialog rather than
Paragraph, so perhaps you should try that instead.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
P

Paul

I put the cursor in one of the pasted bullet paragraphs. I invoked
Format->BulletsAndNumbering->Customize. All the numerical positioning
parameters are zero:

* BulletPosition->IndentAt
* TextPosition->TabSpaceAfter
* TextPosition->IndentAt

That's odd, I thought. So invoked the Reveal Formatting pane from the
Styles and Formatting pane, and sure enough, the Bullets and Numbering
section showed the above three parameters to be zero. According to
Reveal Formatting, the *only* difference between bullets of different
levels is in the Left Indent, in the Paragraph parameters of the
Reveal Formatting pane.

Suzanne, is looking at the Bullets and Numbering pane as described
above what you had in mind?
 
S

Stefan Blom

In Word 97-2003, you must always use the Customize Outline Numbered List dialog
box when setting options for an outline-numbered list, yes.

Note that the recommended approach is to define your lists with a unique
paragraph style attached to each level; you apply (and edit) number formatting
via the Modify Style dialog box for the top-level style. See
http://www.shaunakelly.com/word/numbering/OutlineNumbering.html.

If you are modifying a list that is not associated with styles, place the
insertion point in the first level 1 item before clicking Format | Bullets and
Numbering.

--
Stefan Blom
Microsoft Word MVP
(Message posted via NNTP)



I put the cursor in one of the pasted bullet paragraphs. I invoked
Format->BulletsAndNumbering->Customize. All the numerical positioning
parameters are zero:

* BulletPosition->IndentAt
* TextPosition->TabSpaceAfter
* TextPosition->IndentAt

That's odd, I thought. So invoked the Reveal Formatting pane from the
Styles and Formatting pane, and sure enough, the Bullets and Numbering
section showed the above three parameters to be zero. According to
Reveal Formatting, the *only* difference between bullets of different
levels is in the Left Indent, in the Paragraph parameters of the
Reveal Formatting pane.

Suzanne, is looking at the Bullets and Numbering pane as described
above what you had in mind?
 
P

Paul

Stefan,

The text consists of multilevel bullets, not numbered list items. I
am trying to find and select all bullets of a specific level so that I
can apply a Heading style to them. Does your suggestion still apply?
 
S

Stefan Blom

Paul,

You can set up multilevel/outline bullets via that same dialog box. Just choose
a bullet for "Number style." There are some predefined bullets already in the
drop down box, but if you don't see what you want, click "New Bullet" to select
the desired bullet character.

In this case I'd start with the Modify Style dialog box for Heading 1, setting
up the desired bullet format for each levels, making sure to associate each
level with the corresponding heading style.

However, I don't know of a way to automate the application of styles to text;
that, I'm afraid, will be a manual task.

--
Stefan Blom
Microsoft Word MVP
(Message posted via NNTP)



Stefan,

The text consists of multilevel bullets, not numbered list items. I
am trying to find and select all bullets of a specific level so that I
can apply a Heading style to them. Does your suggestion still apply?
 
S

Suzanne S. Barnhill

The problem here is that the multilevel bullets have already been applied,
presumably to Normal style, and the paragraphs have been progressively
indented to create three different levels. There should be some way to
distinguish among these three levels (which are clearly displayed
differently) in order to search for paragraphs at a specific level and apply
a specific style.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
S

Stefan Blom

My point was that, as far as I know, there is no way in the user interface to do
what the OP is asking for. Maybe it can be automated with VBA.
 
S

Suzanne S. Barnhill

Well, my point was that apparently it can't be done through the UI, either.
I merely contend that it *should* be possible.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
G

Graham Mayor

Even working with vba seems problematical, as the levels associated with the
bullets do not seem to be accessible. However the following macro *may*
help. Put the cursor in one of the bulleted paragraphs in question and all
paragraphs that have the same indent will be formatted with the heading
style number ( 1 - 9) entered into the dialog. The original bullet will be
removed and will only be re-applied if the chosen heading style is bulleted.
The only snag that immediately comes to mind is that there may be unbulleted
paragraphs with the same left indent :(

Sub AddHeadingStyle()
Dim iIndent As Long
Dim iStyle As String
Dim oPara As Paragraph
Start:
On Error Resume Next
iStyle = InputBox("Enter Heading Style number 1-9")
If iStyle = "" Then Exit Sub
iIndent = Selection.Paragraphs(1).LeftIndent
For Each oPara In ActiveDocument.Paragraphs
If oPara.LeftIndent = iIndent Then
oPara.Style = "Heading " & iStyle
End If
Next oPara
End Sub

http://www.gmayor.com/installing_macro.htm
I would recommend testing it on a copy of the document.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

Stefan Blom

Wouldn't testing for

<ParagraphObject>.Range.ListFormat.ListLevelNumber

work?

Even if this works, it won't be 100% reliabe, I guess. A document may contain
several different lists.
 
G

Graham Mayor

It does work after a fashion - but the default body text would be at level 1
(rather than 0 as you might expect)

You can test that premise with a macro containing the line
MsgBox Selection.Range.Paragraphs(1).Range.ListFormat.ListLevelNumber

.... so depending on which level you wanted to exploit you may not get the
results you require, but higher levels should work - and yes it will affect
all the lists, but I had assumed that was the plan i.e. to put some order
into a document by using styles?

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
If oPara.Range.ListFormat.ListLevelNumber = 2 Then
oPara.Style = "Heading 2"
End If
Next oPara

or format all the levels except the first with the matching Heading styles

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
If oPara.Range.ListFormat.ListLevelNumber > 1 Then
oPara.Style = "Heading " & _
oPara.Range.ListFormat.ListLevelNumber
End If
Next oPara

I still cannot think of an elegant way of differentiating the first level
from the underlying text (though there may well be one) but the other macro
I posted earlier would handle level 1

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

OK - found it :)

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
If oPara.Range.ListFormat.ListType = 4 Then
oPara.Style = "Heading " & _
oPara.Range.ListFormat.ListLevelNumber
End If
Next oPara

will format all the levels with their appropriate Heading style

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Paul

Suzanne, Stefan, Graham,

Thanks for your indepth replies...I wasn't expecting to experiment
with VBA, which always takes a while for me to get oriented in, being
not a VBA programmer. I will need to follow up when I have a window
of breathing room (I ploughed through the multilevel bullets and
manually turned them into different-level headings). This is
something that I expect to do more than once, so I have no doubt that
I will be following up with the coding examples at some point.
 
G

Graham Mayor

See http://www.gmayor.com/installing_macro.htm

The posted macro will work with multi-level bulleted (and numbered) lists

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Suzanne, Stefan, Graham,

Thanks for your indepth replies...I wasn't expecting to experiment
with VBA, which always takes a while for me to get oriented in, being
not a VBA programmer. I will need to follow up when I have a window
of breathing room (I ploughed through the multilevel bullets and
manually turned them into different-level headings). This is
something that I expect to do more than once, so I have no doubt that
I will be following up with the coding examples at some point.
 

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