preserving numbering in a SEQ after inserting a new field

S

sjf

I added a new SEQ field to my document:

SEQ thing \# "000"

I copied and pasted this field on several lines yielding the following:

001
002
003

Then I pasted this field again, but between the 001 and 002. The text for
this field shows up as 004, so I have:

001
004
002
003

Then I hit Ctrl-A and F9 to update other fields, and the SEQ fields are
re-numbered so that they are all in order:

001
002
003
004

What do I do to preserve the original numbering when hitting Ctrl-A F9?

Thanks in advance,
sjf
 
S

Stefan Blom

The idea of SEQ fields is that they should be numbered in field order, not
based on the order of insertion.

What you need to do is insert numbers, incremented by 1, that doesn't update
further. This can be accomplished by a macro. For example:

Sub tryout()
'This is a modified version of the code found in the article
'at http://word.mvps.org/faqs/macrosvba/NumberDocs.htm
'by Doug Robbins

Order = System.PrivateProfileString _
("C:\Settings.Txt", _
"MacroSettings", "Order")

If Order = "" Then
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString _
("C:\Settings.txt", _
"MacroSettings", "Order") = Order

Selection.Collapse wdCollapseStart
Selection.InsertAfter Format(Order, "00#")
End Sub

You can use a different path than C:\ for the Settings.txt file if you want
to. Be sure to change it in both locations in the code.

Note that if you need to edit the starting number you can do so by opening
the text file Settings.txt in NotePad or any text editor.

If you are unfamiliar with macros, see
http://www.gmayor.com/installing_macro.htm.
 
S

sjf

thanks stefan, i'll try the macro.

for the record, is there an easy way to save the value of the Order
variable, or any arbitrary data that is used in a macro, in the document
itself?

Cheerios,
sjf
 
G

Graham Mayor

You can store it in a docvariable eg

Sub InsertNextNumber()
Dim oVars As Variables
Dim vVar As Variant
Dim bExists As Boolean
Dim Order As Integer
Set oVars = ActiveDocument.Variables
bExists = False
For Each vVar In oVars
If vVar.name = "varNum" Then
bExists = True
Exit For
End If
Next vVar
If bExists = False Then
oVars("varNum").Value = 0
End If
Order = oVars("varNum").Value
Order = Order + 1
oVars("varNum").Value = Order
With Selection
.InsertBefore Format(Order, "00#")
.Collapse wdCollapseEnd
End With
End Sub

Note that if you are running Word 2007 with all updates, then you will
almost certainly need
http://support.microsoft.com/kb/970942/ for this to work again after saving
and closing the document

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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