Hi guys and gals
im a little stuck on something hopefully i do a decent enough job of explaining my appologies if not.
I found the code below from https://answers.microsoft.com/en-us...r/1b315778-5e81-e011-9b4b-68b599b31bf5?auth=1
The code essentialy creates a .CSV file that records when someone opens or edits the workbook, the .csv is created in the same directory as the workbook
The code works great with my form but id like to be able to ammend the code a little so that the .csv file thats generated is given the hidden atribute so that the file isnt visable to people so they are not tempted to tamper with it. I have tried a few things but i feel this is way above my abilities so any help would be greatly apreciated.
If this isnt possible would anyone know a way to specify a file name that sits in the same folder as the workbook and then changes that files properties to make it a hidden file?
im a little stuck on something hopefully i do a decent enough job of explaining my appologies if not.
I found the code below from https://answers.microsoft.com/en-us...r/1b315778-5e81-e011-9b4b-68b599b31bf5?auth=1
The code essentialy creates a .CSV file that records when someone opens or edits the workbook, the .csv is created in the same directory as the workbook
The code works great with my form but id like to be able to ammend the code a little so that the .csv file thats generated is given the hidden atribute so that the file isnt visable to people so they are not tempted to tamper with it. I have tried a few things but i feel this is way above my abilities so any help would be greatly apreciated.
Code:
Private Sub Workbook_Open()
Const logFile = "LogFile.csv"
Dim logFileName As String
Dim fileBuffer As Integer
logFileName = ThisWorkbook.Path & Application.PathSeparator & logFile
fileBuffer = FreeFile()
'logFile.Attributes = oFile.Attributes Or Hidden Or System
'just in case their is a log jam caused by multiple users
'trying to access the log file at the same time
'ignore the error (record may not be written to the txt file)
'but this file won't crash on them because of it either
On Error Resume Next
Open logFileName For Append As fileBuffer
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=fileBuffer]#fileBuffer[/URL] , Chr$(34) & "Opened:" & Chr$(34) & "," & Chr$(34) & ThisWorkbook.FullName & Chr$(34) & "," _
& Chr$(34) & Application.UserName & Chr$(34) & "," & Chr$(34) & Format(Now(), "dddd, mmmm dd, yyyy hh:mm") & Chr$(34)
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=fileBuffer]#fileBuffer[/URL]
If Err <> 0 Then
Err.Clear
End If
On Error GoTo 0 ' let system or other error trapping function normally
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Const logFile = "LogFile.csv"
Dim logFileName As String
Dim fileBuffer As Integer
Static changeRecorded As Boolean
If changeRecorded Then
Exit Sub
End If
'just in case their is a log jam caused by multiple users
'trying to access the log file at the same time
'ignore the error (record may not be written to the txt file)
'but this file won't crash on them because of it either
On Error Resume Next
logFileName = ThisWorkbook.Path & Application.PathSeparator & logFile
fileBuffer = FreeFile()
Open logFileName For Append As fileBuffer
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=fileBuffer]#fileBuffer[/URL] , Chr$(34) & "Changed:" & Chr$(34) & "," & Chr$(34) & ThisWorkbook.FullName & Chr$(34) & "," _
& Chr$(34) & Application.UserName & Chr$(34) & "," & Chr$(34) & Format(Now(), "dddd, mmmm dd, yyyy hh:mm") & Chr$(34)
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=fileBuffer]#fileBuffer[/URL]
If Err <> 0 Then
Err.Clear
Else
changeRecorded = True
End If
On Error GoTo 0 ' let system or other error trapping function normally
End Sub
If this isnt possible would anyone know a way to specify a file name that sits in the same folder as the workbook and then changes that files properties to make it a hidden file?