CSV file with hidden atribute

Garouken

New Member
Joined
Feb 21, 2017
Messages
7
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.

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?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Thank you !

it works fine when i specify the full location of the file ie "C:\YourFolder\YourFile.csv", however im trying to make it look for the file in the same location as the workbook without providing the full location as the file will be duplicated to various locations. i attemped to use "\YourFile.csv" but i seem to be missing the plot
<wbr>
 
Upvote 0
Thank you !

it works fine when i specify the full location of the file ie "C:\YourFolder\YourFile.csv", however im trying to make it look for the file in the same location as the workbook without providing the full location as the file will be duplicated to various locations. i attemped to use "\YourFile.csv" but i seem to be missing the plot
<wbr>

Figured it out my appologies :P

it was SetAttr ThisWorkbook.Path & "\YourFile.csv", vbHidden
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,700
Members
448,293
Latest member
jin kazuya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top