Reading bullet symbol text from a Word.Range

M

Mike Clayton

Hi,

I've been scratching my head over this for a couple of hours now, so any
help would be appreciated...

I've got some sections in a Word document which are formatted with Bullets
and Numbering so they appears as follows:

1. Section One
2. Section Two
2.1 Subsection A
2.2 Subsection B
2.2.1 Chapter 1
3. Section Three

Using a VBA macro, I'm trying to extract the heading text *including* the
bullet/numbering text (e.g. "2.2 Subsection B") to process it, but all I can
get is the heading "Subsection B" part. I've got a reference to the
Word.Range that contains the "Subsection B" text, but I can't see how to
extract the "2.2" bullet/numbering from there.

I can't find anything in the ParagrahFormat or ListFormat for the Range.
Does anyone know a way of getting this text from the section headings?

Cheers,

Mike
 
M

macropod

Hi Mike,

Like this:
Sub Test()
Dim i As Integer
i = InputBox("Give me a paragraph number to check")
If i > ActiveDocument.Paragraphs.Count Or i = 0 Then
MsgBox "Invalid number"
Else
MsgBox ActiveDocument.Paragraphs(i).Range.ListFormat.ListString
End If
End Sub
 
J

Jialiang Ge [MSFT]

Hello Mike,

To get the numbering string, e.g. "2.1", "2.2.1", we can use the property:
Range.ListFormat.ListString
http://msdn.microsoft.com/en-us/library/bb224117.aspx

Then we can concatenate the numbering string with the heading, e.g.
"Subsection B", to get the whole heading.

Here is an example:
Suppose that "Subsection B" is selected in Word, the following macro pops
up a message box with text "2.2 Subsection B"

Dim numbering As String
numbering = Application.Selection.Range.ListFormat.ListString
Dim heading As String
heading = Application.Selection.Text
MsgBox numbering & heading

Please let me know if you have any other concerns, or need anything else.

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mike Clayton

Thanks macropod, that's exactly what I was looking for.

I must have scrolled past the ListString method about a hundred times in the
VBA Object Browser, but I guess the penny didn't drop. :-S

macropod said:
Hi Mike,

Like this:
Sub Test()
Dim i As Integer
i = InputBox("Give me a paragraph number to check")
If i > ActiveDocument.Paragraphs.Count Or i = 0 Then
MsgBox "Invalid number"
Else
MsgBox ActiveDocument.Paragraphs(i).Range.ListFormat.ListString
End If
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


Mike Clayton said:
Hi,

I've been scratching my head over this for a couple of hours now, so any
help would be appreciated...

I've got some sections in a Word document which are formatted with Bullets
and Numbering so they appears as follows:

1. Section One
2. Section Two
2.1 Subsection A
2.2 Subsection B
2.2.1 Chapter 1
3. Section Three

Using a VBA macro, I'm trying to extract the heading text *including* the
bullet/numbering text (e.g. "2.2 Subsection B") to process it, but all I can
get is the heading "Subsection B" part. I've got a reference to the
Word.Range that contains the "Subsection B" text, but I can't see how to
extract the "2.2" bullet/numbering from there.

I can't find anything in the ParagrahFormat or ListFormat for the Range.
Does anyone know a way of getting this text from the section headings?

Cheers,

Mike
 

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