Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Include Previous Heading Level No. in Word VBA 1

Status
Not open for further replies.

interfact

IS-IT--Management
Jun 11, 2001
12
AU
I used to have some very useful WordBasic macros that I am
now in the process of converting to VBA. Most of the code
converts to VBA well but I am stumped with how to get the
setting for including the number of the previous heading
level for a nominated built-in heading style.

For example, if the Heading1 style uses Arabic numbering
(e.g. 1, 2, 3), I want to be able to determine whether the
Heading2 style is set include the number of the Heading1
style in its numbering (e.g. 1.1, 1.2, 1.3, 2.1, 2.2, 2.3).

This was done with the Include parameter in Wordbasic. The
converted (to VBA) code looks like thisL

'Get include value from H2
Dim FHN As Object: Set FHN =
WordBasic.DialogRecord.FormatHeadingNumber(False)
FHN.Level = 2
WordBasic.CurValues.FormatHeadingNumber FHN
H2IncludePreviousNumber = FHN.include

'Set include value for H2
WordBasic.FormatHeadingNumber
include:=H2IncludePreviousNumber

Interestingly, while I cannot retrieve the include value
I can set it using the above method.

I am quite happy to relinquish the old Wordbasic code but
I cannot for the life of me find out how to do what I want
with VBA.

All suggestions gratefully accepted.
 
On reflection, I could have asked my question a little more clearly.

What I want to know is, using VBA, how can you extract from a nominated heading style whether that heading level is set to have the numbers of preceding heading levels added to it.

That is, what is the setting that specifies that the Heading 2 style should include the number of the Heading 1 style? This isn't a particular number or a numbering style but a Yes or No to include numbering from a previous level.

The Microsoft advice on equivalent Wordbasic - VBA functions says that you should use "ListGalleries(WdListGalleryType).ListTemplates(num).ListLevels(num)" in place of the old Wordbasic FormatHeadingNumber command but I can't see how it can provide what I want.

I would be really glad if someone could solve this for me.

Cheers.
 
Hi interfact,

I don't think you are going to find this one easy.

You need to look at ..

[blue]
Code:
ActiveDocument.Styles("Heading 2").ListTemplate.ListLevels(2).NumberFormat
[/blue]

This will give you a string, probably something like [blue]%1.%2[/blue] which means the level 1 number followed by a period followed by the level 2 number.

However, this string can, in theory, be quite complex (even bizarre, with duplicated elements and elements out of order, etc.) and I wouldn't like to have to extract a lot of information from it.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top