+ Reply to Thread
Results 1 to 3 of 3

Unwanted Carriage Return in output text file

Hybrid View

  1. #1
    Registered User
    Join Date
    11-12-2012
    Location
    Nashville
    MS-Off Ver
    Excel 2007
    Posts
    8

    Unwanted Carriage Return in output text file

    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

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Unwanted Carriage Return in output text file

    try
    Print #OutputFileNum, Line;
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    11-12-2012
    Location
    Nashville
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Unwanted Carriage Return in output text file

    That did it! Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1