View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
jst_se jst_se is offline
external usenet poster
 
Posts: 5
Default Long autonumber beginning with a 0 (zero)

Thank you, Tom!
I tried Worksheets("Blad1").Range("T2") = "0" & x
But your solution was much better and works perfect.

Regards,
Jst

Tom Ogilvy wrote:
Assume you want a 6 digit string and if the value of the number would be 6
digits, you would not want a leading zero.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim x As Boolean, y As Long
y = Worksheets("Blad1").Range("T2").Value + 1
Set fs = CreateObject("Scripting.FileSystemObject")
x = fs.fileexists("C:\indexlog.txt")
If x Then Kill "C:\indexlog.txt"
Open "C:\indexlog.txt" For Output As #1
Print #1, y
Close #1
End Sub

Private Sub Workbook_Open()
Dim x as long
Open "C:\indexlog.txt" For Input As #1
Input #1, x
Close #1
Worksheets("Blad1").Range("T2") = "'" & format( x,"000000")
End Sub



--
Reclaim Your Inbox!
http://www.mozilla.org/products/thunderbird/