snowdance0
New Member
- Joined
- Apr 19, 2022
- Messages
- 5
- Office Version
- 365
- Platform
- Windows
Sub jec()
Dim ar, i As Long, sq As String, xPath As String
ar = Range("A2:B" & Range("A" & Rows.Count).End(xlUp).Row)
xPath = "C:\Users\xx\xx\xxx\"
With CreateObject("scripting.filesystemobject")
For i = 1 To UBound(ar)
sq = xPath & ar(i, 1) & ".txt"
If .FileExists(sq) Then
.createtextfile(sq).write .opentextfile(sq).readall & vbCrLf & ar(i, 2)
Else
.createtextfile(sq).write ar(i, 2)
End If
Next
End With
End Sub
Thank you so much. This work perfectly.Specify your path and it should work.
I assumed that your data is in columns A and B
VBA Code:Sub jec() Dim ar, i As Long, sq As String, xPath As String ar = Range("A2:B" & Range("A" & Rows.Count).End(xlUp).Row) xPath = "C:\Users\xx\xx\xxx\" With CreateObject("scripting.filesystemobject") For i = 2 To UBound(ar) sq = xPath & ar(i, 1) & ".txt" If .FileExists(sq) Then .createtextfile(sq).write .opentextfile(sq).readall & vbCrLf & ar(i, 2) Else .createtextfile(sq).write ar(i, 2) End If Next End With End Sub