With multiple people accessing the same template, I realized you really might need to make the "numbering" part occur compltely during the SaveAs part. So here's the function without the Workbook_Open macro at all. When you do a SaveAs, it will secretly reopen the template, increment the CURRENT number by one, remember it, save the template, put that number into your current workbook, then continue with a normal SaveAs function.
Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim NewVal As Long
With Sheets("Sheet1")
If .Range("AA1") = "" Then
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Workbooks.Open Filename:= _
"C:\Documents and Settings\Jerry\My Documents\Excel Tips\Invoice.xlt", Editable:=True
With ActiveWorkbook.Sheets("Sheet1")
.Range("B2").Value = .Range("B2").Value + 1
NewVal = .Range("B2").Value
End With
ActiveWorkbook.Close True
.Range("B2").Value = NewVal
.Range("AA1") = "Incremented"
Application.ScreenUpdating = True
Application.EnableEvents = True
End If
End With
'normal save continues from here...
End Sub
Bookmarks