I have the following code that works fine and exports the range to csv file
Code: Select all
Dim sFile As String, tmp As String, f As Integer, r As Long, c As Long
sFile = ThisWorkbook.Path & "\Output_" & Format(Now, "dd-mm-yyyy_hh:mm") & ".csv"
f = FreeFile
Open sFile For Output Access Write As #f
With ThisWorkbook.Worksheets("Data")
For r = 1 To .Cells(Rows.Count, "E").End(xlUp).Row
tmp = vbNullString
For c = 5 To 6
tmp = tmp & IIf(tmp = Empty, Empty, ",") & .Cells(r, c).Value
Next c
Print #f, tmp
Next r
End With
Close #f
sFile = ThisWorkbook.Path & "\Output_" & Format(Now, "dd-mm-yyyy_hh:mm") & ".csv"
The csv file is not valid and it seems the extension is not defined to windows while if I used the name directly like that "Output.csv", the code works fine. Any idea?