+ Reply to Thread
Results 1 to 3 of 3

Save n lines in n different files

Hybrid View

  1. #1
    Registered User
    Join Date
    04-22-2015
    Location
    Italia
    MS-Off Ver
    2013
    Posts
    7

    Save n lines in n different files

    Hi guys!

    I'm actually stuck in this problem and honestly I don't think that there is any solution within Excel, but let's give a try.

    This is my situation: I have an excel file with "n" rows (more than 10000 actually), like this:

    333427rc0f8nfw9mcfcw;Hi my name is carl
    2423y98h9nvhf92h2f9h;I like to run
    yf87wgfhqwe8hf;Dont go alone
    dh29h91hd198hdunw9udnq9u;See u soon
    ...
    ...
    ...

    What I actually need, is to find a way to save that rows one by one in .txt files: 1 row = file getting a folder with those "n" files. Is there any chance to do not write a dedicated program to do it?

    Thank you as always guys!

  2. #2
    Forum Contributor
    Join Date
    03-11-2014
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    379

    Re: Save n lines in n different files

    Hi JackNext,

    Let's say column A contains name of the file (notepad) i.e. File1,File2 & so on.
    Column B contains your text.

    The code will pick the text from column B & save it as Notepad with the specified name in column A.

    Sub Export_Files()
        Dim sExportFolder, sFN
        Dim rArticleName As Range
        Dim rDisclaimer As Range
        Dim oSh As Worksheet
        Dim oFS As Object
        Dim oTxt As Object
    
        'sExportFolder = path to the folder you want to export to
        'oSh = The sheet where your data is stored
        sExportFolder = "C:\Users"
        Set oSh = Sheet1
    
        Set oFS = CreateObject("Scripting.Filesystemobject")
    
        For Each rArticleName In oSh.UsedRange.Columns("A").Cells
            Set rDisclaimer = rArticleName.Offset(, 1)
    
            'Add .txt to the article name as a file name
            sFN = rArticleName.Value & ".txt"
            Set oTxt = oFS.OpenTextFile(sExportFolder & "\" & sFN, 2, True)
            oTxt.Write rDisclaimer.Value
            oTxt.Close
        Next
    End Sub
    Change the name of the path where you want to save the file.

    Regards,
    AM
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    04-22-2015
    Location
    Italia
    MS-Off Ver
    2013
    Posts
    7

    Re: Save n lines in n different files

    It works :D Ty so much!

+ 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. [SOLVED] Macro neede to open text files from folder and remove all the lines except specific lines
    By genetist in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-07-2014, 02:44 AM
  2. Replies: 0
    Last Post: 09-09-2014, 05:21 PM
  3. Replies: 2
    Last Post: 08-18-2014, 08:39 PM
  4. [SOLVED] Save/Closed only macro related files and leave unrelated files open in excel?
    By rdowney79 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2013, 04:17 PM
  5. Macro to open *.dat files and save as .txt (comma delimited text files)
    By YehWei@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-30-2005, 01:55 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