CSVファイルを変換出力する(Worksheetを介さない)

Sub CSVconvert()
'//////////////////////////////
'csvをworksheetを介さず変換する
'VBSで十分できる
'//////////////////////////////

Dim fso As Object, inf, outf, aLine, field, wk

'取り込むファイルをダイアログで選択、キャンセルで中断
FileN = Application.GetOpenFilename("CSVファイル,*.csv")
If FileN = False Then Exit Sub

FilecnvName = Left(Dir(FileN), Len(Dir(FileN)) - 4) & "cnv.csv"

Set fso = CreateObject("Scripting.FileSystemObject")
Set inf = fso.OpenTextFile(FileN, 1)
Set outf = fso.OpenTextFile(ThisWorkbook.Path & "\" & FilecnvName, 2, True)

Do Until inf.AtEndOfStream
    aLine = inf.ReadLine
    
'        'セグメント内改行対策箇所
'        Do Until EOF(1)
'            If (Len(strBuf) - Len(Replace(strBuf, """", ""))) Mod 2 = 0 Then Exit Do
'            Line Input #1, strBuf1
'            strBuf = strBuf & strBuf1
'        Loop
'
    '引用符削除
    aLine = Replace(aLine, """,", ",")
    aLine = Replace(aLine, ",""", ",")
    aLine = Replace(aLine, """""", """")
    If Left(aLine, 1) = """" Then aLine = Right(aLine, Len(aLine) - 1)
    If Right(aLine, 1) = """" Then aLine = Left(aLine, Len(aLine) - 1)
        
    'カンマで分割
    field = Split(aLine, ",")
    
'////////////////////////////// 
'処理エリア
'↓並び替えの例
'wk = field(0)
'field(0) = field(1)
'field(1) = field(2)
'field(2) = wk
'//////////////////////////////
headed: '配列をカンマを挟んで結合 aLine = Join(field, ",") 'outfに書き込み outf.WriteLine (aLine) continue: Loop 'ファイルを閉じる inf.Close outf.Close End Sub

Scripting.FileSystemObjectでファイルAをファイルBに変換して出力する。

https://oshiete.goo.ne.jp/qa/1751147.html ←VBS版