You could define a name in your Personal.xls, and use this value when the
template opens, saving Personal.xls when you exit.
Add this code to the template ThisWorkbook code module, and it will
automatically increment the Name UniqueId every time a new workbook is
created from the template.
You canm then Acess that name in your code by plugging this into the
existing code that strings that Id together
Evaluate(Workbooks("Personal.xls").Names("UniqueId ").RefersTo)
Private Sub Workbook_Open()
GetId
End Sub
Private Sub GetId()
Dim myId As Long
myId = 1 ' in case it doesn't already exist
On Error Resume Next
myId = Evaluate(Workbooks("Personal.xls").Names("UniqueId ").RefersTo) +
1
Workbooks("Personal.xls").Names.Add Name:="UniqueId", RefersTo:="=" &
myId
Dim VBCodeMod As Object
Dim iStart As Long
Dim cLines As Long
Set VBCodeMod =
ThisWorkbook.VBProject.VBComponents("ThisWorkbook" ).CodeModule
With VBCodeMod
iStart = .ProcStartLine("GetId", 0)
cLines = .ProcCountLines("MyNewProcedure", 0)
.DeleteLines iStart, cLines
End With
End Sub
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
"Stuart" wrote in message
...
User opens a template (say MasterOrder.xlt). Code in the
ThisWorkbook module of the template increments the
value in "J9" of the template by one, from /1000/ to
/1001/ , the first time through.
So the user now has the workbook "MasterOrder1.xls"
open, sheet "Master Order" is displayed, and on it, cell
"J9" has the value "/1001/".
How do I increment the 'original' template so that next
time through, the new value would be "/1002/" ? because
since the user is only opening a copy of the template, then
the original still holds the value "/1000/".
I only wish to do this if the user chooses to save the file.
If they close without saving, then the original Order
number needs to be preserved.
Regards.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.710 / Virus Database: 466 - Release Date: 23/06/2004