-1

How to output .csv rows to a series of seperate text files?

I saw this link, and the approach should be similar.. Outputting Excel rows to a series of text files

Can anyone help me know the steps and if i should use excel and suggest the steps, to achieve the above results as in the link or otherwise. Thanks in advance...

Community
  • 1
  • 1
Vikas
  • 1
  • Can you give a little more clarification on what your *exact* requirements are? Have you tried anything already? – ZX9 Jul 08 '15 at 15:53
  • The answer to the linked post should work perfectly, if you open that .csv in Excel. – ZX9 Jul 08 '15 at 16:13
  • I have 3 columns: A: Name B:Address C:Zipcode in .csv - I want to covert each row of the csv into a seperate text tile and the content in the columns to become the ''title of the .txt file with a space in between each column text' and generate one seperate .txt file for each row in bulk. I use openoffice calc and don't know what to put in the functions or the steps to accomplish this... – Vikas Jul 09 '15 at 18:03
  • I could open it in excel (calc in openoffice) and save it also. Where do i place/ run the code? thanks ZX9 – Vikas Jul 10 '15 at 10:44
  • Well, if it was really Excel, I'd tell you to start [here](https://msdn.microsoft.com/en-us/library/office/ee814737%28v=office.14%29.aspx). I don't know OpenOffice, but it looks like there are possibilities for [interoperability](https://wiki.openoffice.org/wiki/VBA_interoperability_in_OpenOffice) with VBA... You'd probably be better off learning the OpenOffice language--[Basic](https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide). – ZX9 Jul 10 '15 at 12:01
  • You *really* shouldn't tag this is as [excel](http://stackoverflow.com/questions/tagged/excel). That tag isn't intended for VBA (non-Excel formula-related questions). And, as you **must clarify in your question**, you're dealing with OpenOffice. – ZX9 Jul 10 '15 at 12:04
  • My advice is to see what you can find with `OpenOffice`, try running some code, and, if you have an issue, you can **edit** this question to cover all of that. And there's [this](http://stackoverflow.com/help/how-to-ask). Welcome to StackOverflow! ;) – ZX9 Jul 10 '15 at 12:20
  • Thanks for the reply ZX9. I saw this technique suggested by userid: 2596450 by igalapedia-project here - http://stackoverflow.com/questions/13077740/create-text-files-from-every-row-in-an-excel-spreadsheet?answertab=active#tab-top I have converted to excel, but don't know where to put this code that i given. Where should i execute it? under what menu function in excel? – Vikas Jul 10 '15 at 12:24

1 Answers1

0

Assuming you are actually using Excel now...

First, like I said in one of my comments, you should start here to learn about using Visual Basic for Applications (VBA) on your own.

In Excel, it will be easiest to activate the Developer tab to access the the Visual Basic Editor.

  1. Go to File>Options>Customize the Ribbon.
  2. Check the Developer tab. Click Ok.
  3. Go to Developer and under the Code section is Visual Basic. Click this to open the VBA editor.

Now you can make VBA subs. You can put them in specific sheets, the workbook as a whole, or modules in your PERSONAL.XLSB which allows any Excel workbook with macros enabled to run them.

You may need to create a module. If so:

  1. Right-click on VBAProject (PERSONAL.XLSB).
  2. Insert>Module
  3. Name it.

You can now paste code into the module and you have a "macro".

The easiest way to run this is to

  1. Go to the Developer tab.
  2. Hit Macros.
  3. Select your macro.
  4. Hit Run.

You can also assign a keyboard shortcut by hitting Options... in that same Macros menu.

Now you can essentially copy and paste the code from here. With a slight modification:

Sub Export_Files()
    Dim sExportFolder, sFN
    Dim rTitle As Range
    Dim rContent 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:\Disclaimers"
    Set oSh = Sheet1

    Set oFS = CreateObject("Scripting.Filesystemobject")

    For Each rTitle In oSh.UsedRange.Columns("A").Cells
        Set rContent = rTitle.Offset(, 1) & ", " & rTitle.Offset(, 2)   '<--This will put in your Column B and C value. You can delimit with whatever you desire; I used a comma and space.
        'Add .txt to the article name as a file name
        sFN = rTitle.Value & ".txt"
        Set oTxt = oFS.OpenTextFile(sExportFolder & "\" & sFN, 2, True)
        oTxt.Write rContent.Value
        oTxt.Close
    Next
End Sub
Community
  • 1
  • 1
ZX9
  • 898
  • 2
  • 16
  • 34