Maybe a bit late now the other guys have been quick off the mark, but the
following example will store the number in the registry. If you want to see
how to have individual number sequences for a variety of documents see the
modifications to the registry section at
http://www.gmayor.com/save_numbered_versions.htm
Sub AddNoFromRegistry()
Dim iCount As Integer
Dim WSHShell, RegKey, rkeyWord, Result
Set WSHShell = CreateObject("WScript.Shell")
Dim sDefault As String
Dim sView As String
Dim sCount As String
Start:
RegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Settings\"
On Error Resume Next
rkeyWord = WSHShell.RegRead(RegKey & "AddNo")
If rkeyWord = "" Then
WSHShell.regwrite RegKey & "AddNo", 0
GoTo Start:
End If
sDefault = InputBox("Reset start number?" & vbCr & _
"Enter any character to restart the numbering", "Reset", "No")
If sDefault <> "No" Then
iCount = 1
Else
iCount = Val(rkeyWord) + 1
End If
WSHShell.regwrite RegKey & "AddNo", iCount
' here the code is to print in header the registry value
sView = ActiveWindow.View
ActiveWindow.View = wdPrintView
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
sCount = Format(iCount, "000")
Selection.TypeText Text:=sCount
ActiveWindow.View.SeekView = wdSeekMainDocument
ActiveWindow.View = sView
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>