+ Reply to Thread
Results 1 to 5 of 5

Saving Rows to a txt file with cell separator ?

Hybrid View

  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    South East London
    MS-Off Ver
    2013
    Posts
    3

    Saving Rows to a txt file with cell separator ?

    Hello, I am trying to find a code that will allow me to Save Rows to a txt file with cell seperator ?

    I have put together this from other peoples work online and now all i need to work out is how to add a cell seperator like a comer ?

    Sub WriteTotxt()
    
    Const forReading = 1, forAppending = 3, fsoForWriting = 2
    Dim fs, objTextStream, sText As String
    Dim lLastRow As Long, lRowLoop As Long, lLastCol As Long, lColLoop As Long
    
    lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    For lRowLoop = 1 To lLastRow
    
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set objTextStream = fs.opentextfile("C:\Users\Sam\Desktop\" & Cells(lRowLoop, 1) & ".txt", fsoForWriting, True)
    
        sText = ""
    
        For lColLoop = 1 To 7
            sText = sText & Cells(lRowLoop, lColLoop) & Chr(10) & Chr(10)
        Next lColLoop
    
        objTextStream.writeline (Left(sText, Len(sText) - 1))
    
    
        objTextStream.Close
        Set objTextStream = Nothing
        Set fs = Nothing
    
    Next lRowLoop
    
    End Sub
    Last edited by Malik157; 07-17-2014 at 03:32 AM.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Saving Rows to a txt file with cell separator ?

    What should the output look like in the text file? Currently it is putting every single cell separated by an empty row in a single column?

    your
    
    text
    
    file
    
    looks
    
    like
    
    this
    
    where
    
    should
    
    the
    
    comma
    
    be?
    多么想要告诉你 我好喜欢你

  3. #3
    Registered User
    Join Date
    07-16-2014
    Location
    South East London
    MS-Off Ver
    2013
    Posts
    3

    Re: Saving Rows to a txt file with cell separator ?

    For me the output is just being displayed like this in a text file:

    text1cowchickenbreakfastdiner

    I want to output to be like this:

    text1,cow,chicken,breakfast,diner

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Saving Rows to a txt file with cell separator ?

    I think you can just change this line
    sText = sText & Cells(lRowLoop, lColLoop) & Chr(10) & Chr(10)
    to this
    sText = sText & Cells(lRowLoop, lColLoop) & ","

  5. #5
    Registered User
    Join Date
    07-16-2014
    Location
    South East London
    MS-Off Ver
    2013
    Posts
    3

    Re: Saving Rows to a txt file with cell separator ?

    Thank you worked straight away!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Question on Separator in .csv file
    By faurburg24 in forum Excel General
    Replies: 1
    Last Post: 07-02-2014, 05:06 AM
  2. Replies: 2
    Last Post: 09-07-2012, 12:34 PM
  3. Replies: 4
    Last Post: 07-04-2012, 03:41 PM
  4. Replies: 4
    Last Post: 05-26-2006, 03:10 PM
  5. csv file with special separator
    By morsi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-09-2005, 05:05 AM

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