Append To Text File

  • I would like to append data from Columns A-F to a text file. The key thing is that the data needs to be tab separated just as it would be if I simply highlighted it and copied it and the pasted it into the text file.


    If you need any more information, please let me know and I'll be happy to supply it.


    Your help is appreciated

  • Re: Append To Text File


    Try somewhat like this :


    For iCount = 1 To Range("RowCounter")

  • Re: Append To Text File


    As WinteE suggested you need to build the information within a loop.


    [vba]Sub x()
    Dim lngRow As Long
    Dim lngCol As Long
    Dim strBuf As String
    Dim intUnit As Integer

    intUnit = FreeFile
    Open "filename.txt" For Append As #intUnit

    For lngRow = 1 To 10
    strBuf = ""
    For lngCol = 1 To 6
    strBuf = strBuf & Cells(lngRow, lngCol) & vbTab
    Next
    Print #intUnit, Left(strBuf, Len(strBuf) - 1)
    Next

    Close intUnit

    End Sub
    [/vba]

    [h4]Cheers
    Andy
    [/h4]

  • Re: Append To Text File


    Thanks for this. I have one more question. How can I save the files as a particular name. I would like to save the files using a date field so for example, "item move file 190407.txt". Here is my code that I have so far:


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!