大量にあるcsvファイルを1つのcsvて列方向にまとめたいです。
現在使用しているコードは下記であり、行方向に結合することはできました。
これを行方向ではなく、列方向にまとめる方法はございますでしょうか。
ご回答の程、よろしくお願いいたします。
-----ソースコード-----
Option Explicit
Dim a, c, cr, cv, f, gf, i, j, n(), so, x
Set so = CreateObject("Scripting.FileSystemObject")
Set gf = so.GetFolder(so.GetParentFolderName(WScript.ScriptFullName))
c = - 1
For Each f In gf.Files
If LCase(so.GetExtensionName(f.Name)) = "csv" Then
c = c + 1
ReDim Preserve n(c)
n(c) = f.Name
End If
Next
For i = 0 to c - 1
For j = i + 1 to c
If n(i) > n(j) Then
x = n(i)
n(i) = n(j)
n(j) = x
End If
Next
Next
Set cr = so.OpenTextFile(gf & "\Merge.csv",2 ,True)
For i = 0 to c
Set cv = so.OpenTextFile(gf & "" & n(i), 1)
a = cv.ReadAll
cv.Close
Set cv = Nothing
If i > 0 Then
a = Mid(a, InStr(a, vbCrLf) + 2)
End If
cr.Write a
Next
cr.Close
Set cr = Nothing
Set gf = Nothing
Set so = Nothing
MsgBox("Finished!")