Results 1 to 2 of 2

Thread: export column headers to a CSV file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    302

    export column headers to a CSV file

    I am using this code:
    Write #1, List1.ListItems(i).Text, List1.ListItems(i).ListSubItems(1).Text, _
    List1.ListItems(i).ListSubItems(2).Text, List1.ListItems(i).ListSubItems(3).Text, _
    List1.ListItems(i).ListSubItems(4).Text, List1.ListItems(i).ListSubItems(5).Text


    It works, but there could be more than the 4 rows. Is there a way of exporting this according to the number of columns (each has to be seperated by a comma and has to be one command)?
    Write x, y, z, ...

    I can get the column headers into a temp var, but it copies all headers into a single cell (spreadsheet)

    For i = 1 To List1.ColumnHeaders.Count
    tmpHeaders = tmpHeaders & "," & List1.ColumnHeaders(i).Text
    Next i

    thanks

  2. #2
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    You can just do a count of the number of row and columns that you have and then use a for loop to go through all of items like this untested code:
    You can just do a count of the number of row and columns that you have and then use a for loop to go through all of items like this untested code:
    Code:
        InfoRow = List1.ColumnHeaders(1).Text
        For i = 2 To List1.ColumnHeaders.Count
            InfoRow = InfoRow & "," & List1.ColumnHeaders(i).Text
        Next i
        
        Write #1, InfoRow
       
       
        For i = 1 To List1.ListItems.Count
            InfoRow = List1.ListItems(i).ListSubItems(1).Text
            For j = 2 To List1.ListItems(i).ListSubItems.Count
                InfoRow = InfoRow & "," & List1.ListItems(i).ListSubItems(j).Text
            Next j
            Write #1, InfoRow
        Next i
    This space for rent...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width