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