Results 1 to 4 of 4

Export to text file

Threaded View

  1. #1
    Registered User
    Join Date
    08-09-2011
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    13

    Question Export to text file

    Hello,

    At the moment I have a project where I need to export columns in an Excel file into a text file. This is almost finished. The code I have now saves each row into a separate text file.

    The only thing left to do is to select which columns are exported. Not every column is needed in the text file. It needs to become something like: Column 1,3,5 need to be exported. This is where i need some help.

    Can annyone give me some pointers?

    Here is my code so far:

    
    Sub exporttxt()
    
    Dim firstrow As Integer
    Dim rownum As Integer
    Dim colnum As Integer
    Dim filename As String
    Dim Filelocation As String
    Dim ws As Worksheet
    
    Set ws = Worksheets("form")
    
    Filelocation = "c:\"
    
        With ws
            rownum = 3
            While .Cells(rownum, 1) <> ""
                filename = .Cells(rownum, 1).Value
                Open (Filelocation & filename & ".txt") For Output As #1
                colnum = 2
                
                While .Cells(rownum, colnum) <> 0
                     Print #1, ws.Cells(rownum, colnum) & vbNewLine;
                    colnum = colnum + 1
                    
                Wend
                Close #1
                rownum = rownum + 1
            Wend
            
        End With
    
    End Sub

    Thanks,
    Sebas123
    Last edited by Sebas123; 08-10-2011 at 07:39 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