Results 1 to 10 of 10

Macro to export column header and each row as seperate txt file

Threaded View

  1. #1
    Registered User
    Join Date
    11-12-2012
    Location
    Nashville
    MS-Off Ver
    Excel 2007
    Posts
    8

    Macro to export column header and each row as seperate txt file

    I found a great macro when searching that exports each row to a seperate file perfectly (sorry, didn't get the author to give credit), but I need the column header to be the first line in the text file, then the row of data. Can someone help me with the edit to include that info?

    Sub WriteText()

    Dim firstrow As Integer, rownum As Integer, colnum As Integer
    Dim filename As String
    Dim Filelocation As String
    Dim ws As Worksheet

    Set ws = Worksheets("Sheet1")

    Filelocation = "C:\users\hansenbrad\My Documents\QuestFiles\"

    With ws
    rownum = 2
    While .Cells(rownum, 1) <> ""
    filename = .Cells(rownum, 1).Value
    Open (Filelocation & filename & ".txt") For Output As #1

    colnum = 1
    While .Cells(rownum, colnum) <> 0
    Print #1, ws.Cells(rownum, colnum) & " ";
    colnum = colnum + 1
    Wend
    Close #1
    rownum = rownum + 1
    Wend

    End With

    End Sub
    Last edited by bhansen20; 11-13-2012 at 11:08 AM.

Thread Information

Users Browsing this Thread

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

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