word 2003 vba - get current heading id

N

nerfemail

Hi,

I need your help. I spent many hours and have not found a solution for
my problem.
I have a big word 2003 document. It has many headings (up to 5+ levels
deep). It also has bullets (lists).

I found a piece of code, that lets me place all the headings in a
listbox, but I don't know how to select the current (cursor) heading
in the listbox.

I tried to get the current heading text, but some heading titles
contain the same text.

Is it possible to get the heading ID? So that I can use
listbox1.listindex=HeadingID? Can you help?

Thank you


POPULATING THE LISTBOX:
varRefType = WdReferenceType.wdRefTypeHeading
varXRefs =
ActiveDocument.GetCrossReferenceItems(ReferenceType:=varRefType)
For Index = 1 To UBound(varXRefs)
Me.ListBox1.AddItem varXRefs(Index)
Next Index

DOCUMENT:

1 HEADING ONE TITLE
- bullet list
1.1 HEADING TITLE
* mouse cursor is here (should select this entry when adding to
listbox)
2 HEADING TITLE
etc.
 
D

Doug Robbins - Word MVP

With Selection.Paragraphs(1).Range
MsgBox .ListFormat.ListString & " " & .Text
End With

Displays the number applied to the heading and its text

So you will probably need to load your listbox with the

..Range.ListFormat.ListString & " " & .Text

of each heading so that you can then identify the item in the listbox that
matches the heading in which the cursor is located.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
N

nerfemail

With Selection.Paragraphs(1).Range
     MsgBox .ListFormat.ListString & "  " & .Text
End With

Displays the number applied to the heading and its text

So you will probably need to load your listbox with the

.Range.ListFormat.ListString & " " & .Text

of each heading so that you can then identify the item in the listbox that
matches the heading in which the cursor is located.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

Thanks Doug, but I had tried that. If the cursor is over a bullet
list, it returns "?" followed by the bullet text.

I found another way; very messy. I get the entire text from the
current heading and then parse it to get the heading title...
 
D

Doug Robbins - Word MVP

Your post only asked about getting the current heading, not an item in a
bulleted list.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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