Thanks to Mike7952, I am using a Macro he provided to export to a text file, but the resulting files have a carriage return on the end of the last line in the file. Is there a way to prevent this, or a way to remove the carriage return from Many files?
Option Explicit
Sub WriteFile()
Const shRawData As String = "Sheet1"
Dim LineValues() As Variant, Line As String
Dim OutputFileNum As Integer
Dim PathName As String
Dim i As Long, ii As Long
Dim a, aheaders
PathName = "C:\users\hansenbrad\My Documents\QuestFiles\"
With Worksheets(shRawData)
a = .Range("a1").CurrentRegion.Value
End With
ReDim LineValues(1 To UBound(a, 2))
For ii = 1 To UBound(a, 2)
LineValues(ii) = a(1, ii)
Next
aheaders = Join(LineValues, vbTab)
For i = 2 To UBound(a)
OutputFileNum = FreeFile
Open PathName & a(i, 2) & ".txt" For Output Lock Write As #OutputFileNum
ReDim LineValues(1 To UBound(a, 2))
For ii = 1 To UBound(a, 2)
LineValues(ii) = a(i, ii)
Next
Line = Join(LineValues, vbTab)
Print #OutputFileNum, aheaders
Print #OutputFileNum, Line
Close OutputFileNum
Next
End Sub
Bookmarks