Results 1 to 2 of 2

Thread: CSV to Excel Document

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    CSV to Excel Document

    I found the following code on the forums...

    VB Code:
    1. Dim exl As Excel.Application
    2.         [b]exl = New Excel.Application[/b]
    3.         exl.Workbooks.OpenText("myfile.csv")
    4.         exl.Workbooks.Close()
    5.         exl = Nothing

    It isn't working. It says that I can't use "New" on the bolded line because Excel.Application is an interface.

    What do I do?

    Thanks,

    Squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  2. #2
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098
    I am also in dire need of this knowledge ...please help anyone...!

    VB Code:
    1. Private Sub btnSendToExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendToExcel.Click
    2.         'Initializes Excel and creates a new workbook/worksheet
    3.         Dim excelApp As New Excel.Application
    4.         Dim excelBook As Excel.Workbook = excelApp.Workbooks.Add
    5.         Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
    6.         'Makes Excel invisible to the user until spreadsheet is populated
    7.         excelApp.Visible = False
    8.         With excelWorksheet
    9.  
    10.  
    11.             Dim i As Integer = 2
    12.  
    13.             'Format cell headings
    14.  
    15.             .Range("A1").Value = "First Name"
    16.             .Range("B1").Value = "Last Name"
    17.             .Range("C1").Value = "Address"
    18.  
    19.             'Populate Excel spreadsheet
    20.             Try
    21.  
    22.                 .Range("A" & i.ToString).Value = "fname"
    23.                 .Range("B" & i.ToString).Value = "lname"
    24.                 .Range("C" & i.ToString).Value = "address"
    25.                 i += 1
    26.  
    27.             Catch ex As Exception
    28.  
    29.             End Try
    30.             'Make Excel visible
    31.             excelApp.Visible = True
    32.         End With
    33.  
    34.     End Sub

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