Forgive me in advance, but I have a word.dot and have managed to get the code to insert a unique receipt number sequentially into the header of the document on open, trouble is I need to also find a way of stopping the code from running again and again once it has created an invoice number as when ever someone else opens the doc it runs again and the code overwrites the originally created number with a new one, has anyone came across or solved this in the past and knows how to get around it, i thought of using the system date/time but not sure how to implement this
Code:
Dim path As String
path = "\Documents\Contracts\"
Order = System.PrivateProfileString("\Documents\Contracts\settings.txt", "macrosettings", "Order")
With ActiveDocument.Bookmarks
.Add Name:="Order"
End With
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If
System.PrivateProfileString("\\Documents\Contracts\settings.txt", "MacroSettings", _
"Order") = Order
ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Order, "7000#")
'ActiveDocument.SaveAs FileName:=path & Format(Order, "00#")
End Sub