Automatic Caption Numbering

A

andreas

Dear Experts:

I wrote two macros that insert figure caption numbering automatically
by using AutoText entries:

The macros go as follows:

1. Automatic Caption numbering for figures directly following heading
level 1:

Application.DisplayAutoCompleteTips = True

ActiveDocument.AttachedTemplate.AutoTextEntries("Caption_Numbering_1").Insert
_
Where:=Selection.Range, RichText:=True

Result: e.g.,
"Figure" 2-1: .......
The field code behind the autotext entry:
"Figure" {STYLEREF Custom_Heading_Style_Level_1 \s}-{SEQ Figure \*
ARABIC \r 1}: .......


2. Automatic Caption numbering for figures that are counted
sequentially after the first one within a chapter

Application.DisplayAutoCompleteTips = True

ActiveDocument.AttachedTemplate.AutoTextEntries("Caption_Numbering_2").Insert
_
Where:=Selection.Range, RichText:=True

Example:
"Figure" 2-2: ........
The field codes behind the AutoTextEntries are as follows:
"Figure" {STYLEREF Custom_Heading_Style_Level_1 \s}-{SEQ Figure \*
ARABIC}: .......

Now here comes my question:
Is it possible to merge these two macros into just one, i.e. whenever a
caption numbering is inserted the macro should check within a given
chapter (1,2,3 etc.) whether the inserted figure or table is the first
one in this chapter, i.e. {STYLEREF Custom_Heading_Style_Level_1}-{SEQ
Bild \* ARABIC \r 1} or not ({STYLEREF
Custom_Heading_Style_Level_1}-{SEQ Bild \* ARABIC}).

I hope I did make myself clear. Help is appreciated.

Thanks in advance.

Regards,

Andreas
 
S

Shauna Kelly

Hi Andreas

Yes, you could write code to do this. Basically, you need to use .Find to
look backwards through the document to see if you find a paragraph in style
Custom_Heading_Style_Level_1 before you find a field that includes "SEQ
Figure". If you decide to do that, I advise turning on the display of Field
Codes to search for the field codes, rather than relying on the
..TextRetrievalMode (look these up in VBA Help for more info).

Bear in mind that, if you create captions like this, you won't be able to
create meaningful cross-references to them, and you won't be able to create
a table of figures.

Overall, what you're doing is a complicated way of reinventing the wheel. If
you use the built-in heading styles (modified to suit your needs), then none
of this is necessary, since Word will do all the work for you when you do
Insert > Reference > Caption.

For 13 other reasons to use the built-in heading styles, see
Why use Microsoft Word's built-in heading styles?
http://www.ShaunaKelly.com/word/numbering/UseBuiltInHeadingStyles.html

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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