Automatic "non-sequential" numbering in a requirements specification?

V

vince.public

I'm trying to create a Word template for a requirements specification,
but I'm going nuts trying to figure out if I can cajole/beg/strong-arm
Word into handling something for me...

Let's say I define a style to be used for formatting a requirement
(call it "Requirement"... duh). Now in the simplest use of this style,
I could have a multiple paragraphs tagged with this style and can get
them to automatically be numbered in sequential order, e.g.:

REQ-1: blah blah blah
REQ-2: blah blah blah

(some filler text)

REQ-3: blah blah blah

(more filler text)

(etc.)

Now let's say I need to insert a new Requirement instance between the
existing REQ-1 and REQ-2 above. When I do this now, the new instance
becomes REQ-2; the old REQ-2 becomes REQ-3, the old REQ-3 becomes
REQ-4, etc. What I would *like* to do instead is have this new
instance be automatically numbered as REQ-4 (or whatever the next
highest "available" value is for this style).

Similarly, let's say that I delete REQ-3 above and add a new
Requirement instance somewhere. That new instance now becomes REQ-3,
but I'd *like* to have it be auto-numbered as REQ-4 (or whatever the
next highest "available value is for this style).

Can either/both of these behaviors be affected via... I don't know
what -- macros? clever use of [custom?] fields? magic?

Thanks,
- Vince
 
S

Stefan Blom

Something like this could be used:

Const CustomPath$ = "H:\settings.txt"
Sub InsertNumber()

'This is a modified version of the macro at
'http://word.mvps.org/faqs/macrosvba/NumberDocs.htm
'(by Doug Robbins)

Dim Order As String

Order = System.PrivateProfileString(CustomPath, _
"MacroSettings", "Order")

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

System.PrivateProfileString(CustomPath, "MacroSettings", _
"Order") = Order

Selection.InsertAfter "REQ-" & Order
Selection.Collapse wdCollapseEnd

End Sub

Note 1: The "current" number is stored in a text file (settings.txt). I used
"H:\settings.txt" as the full path for the text file. You should specify a
path that is relevant on your system.

Note 2: If you want to change the number set by the macro, for example when
you are creating a new document, just edit the number in the settings.txt
file.

Note 3: If you need installation instructions, see
http://www.gmayor.com/installing_macro.htm.
 
S

Stefan Blom

If numbering should be document-specific, you can make use of these macros
instead (place them in the attached template):

Sub InsertNumberInDoc()
Dim v As Variable
If VarExists("test") = False Then
ActiveDocument.Variables.Add "test", 0
End If

Set v = ActiveDocument.Variables("test")

If IsNumeric(v.Value) And v.Value >= 0 Then
v.Value = v.Value + 1
Else
v.Value = 1
End If

Selection.InsertAfter "REQ-" & v.Value
Selection.Collapse wdCollapseEnd

End Sub

Function VarExists(VarName As String) As Boolean
Dim v As Variable
For Each v In ActiveDocument.Variables
If v.Name = VarName Then
VarExists = True
Exit Function
End If
Next v
End Function

Attach the InsertNumberInDoc sub-routine to a toolbar button (Word 97-2003)
or add it to the Quick Access Toolbar (Word 2007). Also, you can assign a
keyboard shortcut.

See also http://www.gmayor.com/installing_macro.htm.

--
Stefan Blom
Microsoft Word MVP


in message
Something like this could be used:

Const CustomPath$ = "H:\settings.txt"
Sub InsertNumber()

'This is a modified version of the macro at
'http://word.mvps.org/faqs/macrosvba/NumberDocs.htm
'(by Doug Robbins)

Dim Order As String

Order = System.PrivateProfileString(CustomPath, _
"MacroSettings", "Order")

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

System.PrivateProfileString(CustomPath, "MacroSettings", _
"Order") = Order

Selection.InsertAfter "REQ-" & Order
Selection.Collapse wdCollapseEnd

End Sub

Note 1: The "current" number is stored in a text file (settings.txt). I
used
"H:\settings.txt" as the full path for the text file. You should specify a
path that is relevant on your system.

Note 2: If you want to change the number set by the macro, for example
when
you are creating a new document, just edit the number in the settings.txt
file.

Note 3: If you need installation instructions, see
http://www.gmayor.com/installing_macro.htm.

--
Stefan Blom
Microsoft Word MVP


I'm trying to create a Word template for a requirements specification,
but I'm going nuts trying to figure out if I can cajole/beg/strong-arm
Word into handling something for me...

Let's say I define a style to be used for formatting a requirement
(call it "Requirement"... duh). Now in the simplest use of this style,
I could have a multiple paragraphs tagged with this style and can get
them to automatically be numbered in sequential order, e.g.:

REQ-1: blah blah blah
REQ-2: blah blah blah

(some filler text)

REQ-3: blah blah blah

(more filler text)

(etc.)

Now let's say I need to insert a new Requirement instance between the
existing REQ-1 and REQ-2 above. When I do this now, the new instance
becomes REQ-2; the old REQ-2 becomes REQ-3, the old REQ-3 becomes
REQ-4, etc. What I would *like* to do instead is have this new
instance be automatically numbered as REQ-4 (or whatever the next
highest "available" value is for this style).

Similarly, let's say that I delete REQ-3 above and add a new
Requirement instance somewhere. That new instance now becomes REQ-3,
but I'd *like* to have it be auto-numbered as REQ-4 (or whatever the
next highest "available value is for this style).

Can either/both of these behaviors be affected via... I don't know
what -- macros? clever use of [custom?] fields? magic?

Thanks,
- Vince
 
V

vince.public

@askteam: My work is already being done in the context of templates,
but those were still a couple of useful links -- thanks!

@Stefan: Thanks for the detailed info! I'll definitely give those
(probably the 2nd option) a go.

- Vince
 

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