Getting Current Paragraph "Level" 
Author Message
 Getting Current Paragraph "Level"

Hi All.

Word can create numbered headings (paragraphs) such as:

1 Heading 1
1.1 Heading 2
1.1.1 Heading 3
1.2 Heading 2
1.2.1 Heading 3
2 Heading 1
2.1......

When scanning through a document, selecting sentences, and coming across a
heading, is there a method to detect the level (Like recovering a string of
"1.1.2.1" ) of the current selection??
 I don't see any direct reference to this in the VBA Methods references

I thank you in advance




Mon, 29 Dec 2003 11:07:23 GMT  
 Getting Current Paragraph "Level"
Hi Bri

You need the OutlineLevel property.

x = Selection.ParagraphFormat.OutlineLevel

will put the outline level into x. The property returns 1 to 9 for heading
levels 1-9, 10 for body text, and something like 99999 where the selection
spans paragraphs with more than one outline level.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email


Quote:
> Hi All.

> Word can create numbered headings (paragraphs) such as:

> 1 Heading 1
> 1.1 Heading 2
> 1.1.1 Heading 3
> 1.2 Heading 2
> 1.2.1 Heading 3
> 2 Heading 1
> 2.1......

> When scanning through a document, selecting sentences, and coming across a
> heading, is there a method to detect the level (Like recovering a string
of
> "1.1.2.1" ) of the current selection??
>  I don't see any direct reference to this in the VBA Methods references

> I thank you in advance





Mon, 29 Dec 2003 16:31:47 GMT  
 Getting Current Paragraph "Level"
Hi Bri,

The following code will load the variable named Hlevel with the heading
level of the heading in which the selection is located

Dim Hlevel As String
If Left(Selection.Style, 7) = "Heading" Then
    ActiveDocument.ConvertNumbersToText
    Hlevel = Left(ActiveDocument.Bookmarks("\line").Range,
InStr(ActiveDocument.Bookmarks("\line").Range, vbTab) - 1)
    ActiveDocument.Undo
    MsgBox Hlevel
End If

Please post any follow-up or new questions to the Newsgroups so that others
may benefit therefrom or contribute thereto.

Hope this helps,
Doug Robbins - Word MVP

Quote:
> Hi All.

> Word can create numbered headings (paragraphs) such as:

> 1 Heading 1
> 1.1 Heading 2
> 1.1.1 Heading 3
> 1.2 Heading 2
> 1.2.1 Heading 3
> 2 Heading 1
> 2.1......

> When scanning through a document, selecting sentences, and coming across a
> heading, is there a method to detect the level (Like recovering a string
of
> "1.1.2.1" ) of the current selection??
>  I don't see any direct reference to this in the VBA Methods references

> I thank you in advance





Mon, 29 Dec 2003 17:51:34 GMT  
 Getting Current Paragraph "Level"
Hi Doug

The simplest way to get the heading number is to use ListString:

MsgBox Selection.Paragraphs(1).Range.ListFormat.ListString

(As Jonathan says, to get the outline level you use the Outline Lrevel
property, and I'm not certain which Bri actually wants).

Regards

Dave


| Hi Bri,
|
| The following code will load the variable named Hlevel with the heading
| level of the heading in which the selection is located
|
| Dim Hlevel As String
| If Left(Selection.Style, 7) = "Heading" Then
|     ActiveDocument.ConvertNumbersToText
|     Hlevel = Left(ActiveDocument.Bookmarks("\line").Range,
| InStr(ActiveDocument.Bookmarks("\line").Range, vbTab) - 1)
|     ActiveDocument.Undo
|     MsgBox Hlevel
| End If
|
| Please post any follow-up or new questions to the Newsgroups so that
others
| may benefit therefrom or contribute thereto.
|
| Hope this helps,
| Doug Robbins - Word MVP

| > Hi All.
| >
| > Word can create numbered headings (paragraphs) such as:
| >
| > 1 Heading 1
| > 1.1 Heading 2
| > 1.1.1 Heading 3
| > 1.2 Heading 2
| > 1.2.1 Heading 3
| > 2 Heading 1
| > 2.1......
| >
| > When scanning through a document, selecting sentences, and coming across
a
| > heading, is there a method to detect the level (Like recovering a string
| of
| > "1.1.2.1" ) of the current selection??
| >  I don't see any direct reference to this in the VBA Methods references
| >
| > I thank you in advance
| >

|
|



Mon, 29 Dec 2003 19:15:27 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Printing a paragraph like "word wrap"

2. Looking for "Novice" level VB Programmers

3. Multiple-level "Implements"

4. form level "Changed_Event"

5. Determining "level" of selected tree node

6. Determining "level" of selected tree node

7. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

8. Problem understanding "Current Record" on form

9. "Operation invalid without current index"

10. Combine 2 "On Current"

11. "No current record" woes in DAO

12. "Reset the current code" error message

 

 
Powered by phpBB® Forum Software