johnske
05-01-2005, 05:37 PM
Hi,
I've been playing around with the idea of having a 'hidden' text file to secretly log all the dates and times that a workbook has been opened. I have the code below, but this only writes the last time it's been opened (overwriting the previous entry)...
So - I want to know how you add a new line to the text file (leaving the previous entries unchanged) to insert the current time/date?
Private Sub Workbook_Open()
Dim DateOpened$, NewFile$
DateOpened = Format(Now, "dd mmm yyyy hh:mm:ss")
On Error GoTo CreateFile
MakeEntry:
Open "c:\" & Left(ThisWorkbook.Name, _
Len(ThisWorkbook.Name) - 4) & _
" LogFile.txt" For Output As #1
Write #1, "Accessed: " & DateOpened
Close #1
Exit Sub
CreateFile:
If Err.Number = 53 Then '=LogFile file does not exist...
NewFile = "Create 'C:\" & Left(ThisWorkbook.Name, _
Len(ThisWorkbook.Name) - 4) & _
" LogFile.txt' File"
Resume MakeEntry
End If
Resume Next
End Sub
TIA
John
I've been playing around with the idea of having a 'hidden' text file to secretly log all the dates and times that a workbook has been opened. I have the code below, but this only writes the last time it's been opened (overwriting the previous entry)...
So - I want to know how you add a new line to the text file (leaving the previous entries unchanged) to insert the current time/date?
Private Sub Workbook_Open()
Dim DateOpened$, NewFile$
DateOpened = Format(Now, "dd mmm yyyy hh:mm:ss")
On Error GoTo CreateFile
MakeEntry:
Open "c:\" & Left(ThisWorkbook.Name, _
Len(ThisWorkbook.Name) - 4) & _
" LogFile.txt" For Output As #1
Write #1, "Accessed: " & DateOpened
Close #1
Exit Sub
CreateFile:
If Err.Number = 53 Then '=LogFile file does not exist...
NewFile = "Create 'C:\" & Left(ThisWorkbook.Name, _
Len(ThisWorkbook.Name) - 4) & _
" LogFile.txt' File"
Resume MakeEntry
End If
Resume Next
End Sub
TIA
John