PDA

View Full Version : Requirements Numbering Macro



joe
12-08-2005, 11:12 AM
All,

Here's a 'tool' that I created for you to use in your next big requirements document. It is a macro that will uniquely number each requirement in your document and keep a running counter so you never number two requirements the same. This counter is saved every time you save the doc.

To use it, just make a macro in MS Word and paste this code into the VB code editor. Every time you write a requirement, use the terminology "FR XXX" and this macro will find that and replace it with the next number in the sequence.

Please don't take credit for this anywhere else. [insert copyright disclaimer here] :)

Let me know what you think!


Sub numberRequirements()
'
' numberRequirements Macro
' Macro recorded 1/28/2005 by Joe Shideler (Seilevel)
'
num = 0
For Each aVar In ActiveDocument.Variables
If aVar.Name = "ReqNumber" Then num = aVar.Index
Next aVar
If num = 0 Then
ActiveDocument.Variables.Add Name:="ReqNumber", Value:=1
Else
ActiveDocument.Variables(num).Value = ActiveDocument.Variables("ReqNumber").Value
End If

numbering = ActiveDocument.Variables("ReqNumber").Value

If numbering < 10 Then
requirement = "FR 00" + numbering
Else
If numbering < 100 Then
requirement = "FR 0" + numbering
Else
If numbering > 99 Then
requirement = "FR " + numbering
End If
End If
End If

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "FR XXX"
.Replacement.Text = requirement
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
End With

ActiveDocument.Variables("ReqNumber").Value = numbering + 1

End Sub

joe

prompolp
07-20-2006, 09:08 AM
Great Macro. Although, it would be nice if the Marco updated all the requirement tolkens (FR XXX) for the entire document. Currently for me it's just numbering one requirement everytime I run the Macro.

I'm running MSOffice 2003 on WinXP SP2.

Thanks

joe
05-08-2008, 12:50 PM
Just wanted to bump this thread because I used this again today and I'm still finding it very useful.

It's compatible with Office 2007! :)

joe

MGoyal
05-11-2008, 08:59 PM
Nice job joe!