I have the following code working in such that it will create a new number with increments of 1 each time the document is opened however the document I have is a contract template. What I need is the template to create a new number when its opened and then once its been saved the new saved document keeps the number given to it i.e the contract number remains constant as its important that it doesn't change.

So I guess I need some way for the code to stop working once it knows its been saved if thats possible? I know its possible in Word as this is originally where the contracts were created however our team are wishing to change them into Excel for the additional features Excel gives us but this is a stumbling block if it doesn't work. The contract number comes from a text document called "defaultseq.txt" and I am using Excel 2003.

Public Sub Workbook_Open()
ThisWorkbook.Sheets(1).Range("ad4").Value = NextSeqNumber
End Sub

Public Function NextSeqNumber(Optional sFileName As String, Optional nSeqNumber As Long = -1) As Long
Const sDEFAULT_PATH As String = "C:\Documents and Settings\cmansfie\Desktop\macro"
Const sDEFAULT_FNAME As String = "defaultseq.txt"
Dim nFileNumber As Long

nFileNumber = FreeFile
If sFileName = "" Then sFileName = sDEFAULT_FNAME
If InStr(sFileName, Application.PathSeparator) = 0 Then _
sFileName = sDEFAULT_PATH & Application.PathSeparator & sFileName
If nSeqNumber = -1& Then
If Dir(sFileName) <> "" Then
Open sFileName For Input As nFileNumber
Input #nFileNumber, nSeqNumber
nSeqNumber = nSeqNumber + 1&
Close nFileNumber
Else
nSeqNumber = 1&
End If
End If
On Error GoTo PathError
Open sFileName For Output As nFileNumber
On Error GoTo 0
Print #nFileNumber, nSeqNumber
Close nFileNumber
NextSeqNumber = nSeqNumber
Exit Function
PathError:
NextSeqNumber = -1&
End Function
A lot of the above I don't know what it is doing as I am a novice to VBA programming however I have managed to get it working almost as I needed to.

Any help very much appreciated. The problem I have mainly is I don't know if I need extra code or whether there's something I can alter thats already there!

Cheers, Chris