Option Explicit
Public Sub CSV()
Const ForReading = 1
Const ForWriting = 2
Dim i As Long
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim strFolder As String
strFolder = "D:\Test VBA\CSV"
Dim oFile As Variant
Dim oCSV As Variant
Dim strCSV As String, strNew As String
Dim arr As Variant
If Not fso.FolderExists(strFolder) Then
Set fso = Nothing
Exit Sub
End If
If Not fso.FolderExists(fso.BuildPath(strFolder, "Output")) Then
fso.CreateFolder (fso.BuildPath(strFolder, "Output"))
End If
For Each oFile In fso.GetFolder(strFolder).Files
If UCase(fso.GetExtensionName(oFile.Path)) = "CSV" Then
Set oCSV = fso.OpenTextFile(oFile.Path, ForReading)
strNew = ""
Do While Not oCSV.AtEndOfStream
strCSV = oCSV.ReadLine
arr = Split(strCSV, ",")
strNew = strNew & arr(0) & "," & arr(2) & "," & arr(5) & vbCrLf
Loop
oCSV.Close
Debug.Print strNew
Set oCSV = fso.CreateTextFile(fso.BuildPath(fso.BuildPath(strFolder, "Output"), oFile.Name), True)
oCSV.Write (strNew)
oCSV.Close
End If
Next oFile
Set oCSV = Nothing
Set fso = Nothing
End Sub