Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outputting Excel rows to a series of text files

Inside Excel, I have a list of article names in column A, and a disclaimer inside column B. Now for each article in column A, I would like to create a text file, were A is the title of the file and B, the disclaimer, is the contents of the file.

Is this possible?

The idea is that I have several hundred of these, and I would like to make this easier on myself.

If Excel is not ideal for this, can anyone suggest an alternative? (possibly Notepad++ has a feature that can help?)

like image 993
SmokingKipper Avatar asked Aug 22 '11 15:08

SmokingKipper


People also ask

How do I export certain rows in Excel?

Start off by opening up the list page that you want to export the rows from and select the rows that you want to export. Then right-mouse-click on the check marks beside the records. When the context menu is displayed, there will be two new options that show up. Export all rows and also Export marked rows.

How do I convert a text file to rows and columns in Excel?

Open the Excel spreadsheet where you want to save the data and click the Data tab. In the Get External Data group, click From Text. Select the TXT or CSV file you want to convert and click Import.


1 Answers

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:\Disclaimers"
    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
like image 58
transistor1 Avatar answered Sep 26 '22 00:09

transistor1