Insert the following DOCVARIABLE field in the document where you want the number to appear: { DOCVARIABLE VarNum \# "'BIR-'000000" }
Add the following macro to the document and save as a macro enabled document:
Code:
Sub AutoOpen()
Dim oVars As Variables
Dim bVar As Boolean
Dim lngCount As Long
Set oVars = ActiveDocument.Variables
For Each oVar In ActiveDocument.Variables
If oVar.Name = "varNum" Then
bVar = True
lngCount = oVar.Value + 1
Exit For
End If
Next oVar
If Not bVar Then lngCount = 1
oVars("varNum").Value = lngCount
UpdateAllFields
ActiveDocument.Save
lbl_Exit:
Exit Sub
End Sub
Private Sub UpdateAllFields()
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
lbl_Exit:
Exit Sub
End Sub
If you need to change the number set the value of the document variable 'varNum' as required.
A simple way to do this is to use
http://www.gmayor.com/BookmarkandVariableEditor.htm
See also
http://www.gmayor.com/automatic_numbering_documents.htm for two other methods that may be adapted to your requirements.