PDA

View Full Version : Automatic caption field codes



Lipanook
07-04-2013, 04:51 AM
I am creating a Word 2007 template for a document where most of the actual content is in the appendices. In the main body of the document (i.e. the bit preceding the appendices), the figure and table legends have the format: Figure 1.1., where the 1st number is the section (based on Heading 1), and the second number is the figure number (resetting to 1 in the next section). All pretty standard stuff.

The problem I encounter is wen it comes to putting in figure legends for the appendices. The formatting for these should be Figure I.1., where the letter is the appendix number in Roman numerals and the number is the figure number (resetting to 1 in the next appendix).

Below is the code that I have already written, which puts in a figure legend/caption in an appendix. It half works. The Roman numeral it does fine, but the figure number is the bit that is causing a problem. Instead of resetting to 1 at the start of a new appendix, it is just carrying on numbering from the last section that begins with the "Heading 1" style.

The trouble is that the \s switch that I have used in the field code is based on the style "Heading 1", when what I want it to do is be based on the style "AppendixHead1", like the Roman numeral.

Can anybody suggest a fix for this?

Current code:

Sub appendixFigure()
With Selection
.Style = ActiveDocument.Styles("Caption")
.TypeText Text:="Figure "
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="STYLEREF AppendixHead1 \s", PreserveFormatting:=False
.TypeText Text:="."
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="SEQ Figure \* ARABIC \s 1", PreserveFormatting:=False
End With

End Sub

Doug Robbins
07-09-2013, 12:23 AM
See the following page of the Late Shauna Kelly's website:

http://www.shaunakelly.com/word/numbering/numberingappendixes.html

JamesAl
07-09-2013, 01:44 AM
I agree with Doug, The link given will help you.

Lipanook
07-09-2013, 02:27 AM
Thanks for that link.

While I was waiting for a reply to this thread I came up with a relatively simple work around, which seems to be working just fine.

I have set up Headings 6 - 8 (which were not in use) as my Appendix Headings, and changed the number after the switch to 6 instead of 1.