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
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