You don't "clear the contents". You overwrite the file.
First you open the file and read the first line (the header).
Then you create a new file with the same name and write the header which overwrites the file, effectively "clearing the contents".
In the IDE, go to TOOLS/References. Scroll down an put a check box in front of 'Microsoft Office x.x Object Library".
In A2010, the x.x number is 14.0. Maybe A2013 is 15.0??
Then use the following code. I named the sub "ClearCSV', but you can use your button name or rename it to whatever you want.
Code:
' requires a Reference to Microsoft Office x.x Object Library
Public Sub ClearCSV()
'-----begin code ----------------------
Dim fd As Office.FileDialog
Dim strFileName As String
Dim HeaderText As String
Dim TF As Integer
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Filters.Clear
'only show CSV files
fd.Filters.Add "CSV Files", "*.csv"
fd.InitialFileName = CurrentProject.Path
'MsgBox CurrentProject.Path
'select a file
If fd.Show Then
strFileName = fd.SelectedItems(1)
Else
MsgBox "No File Selected! Goodbye....." '<<-- you can change to your message
Exit Sub
End If
'open the file and read in the header
TF = FreeFile
Open strFileName For Input As #TF
Line Input #TF, HeaderText ' Read header line into variable.
Close #TF
' overwrite the file and write the header
TF = FreeFile
Open strFileName For Output As #TF
'write the header
Print #TF, HeaderText
Close #TF
'clean up
Set fd = Nothing
'-----end code -------------------------
End Sub
Note: there is no error handling in this routine....