Private Sub btnSendToExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendToExcel.Click
'Initializes Excel and creates a new workbook/worksheet
Dim excelApp As New Excel.Application
Dim excelBook As Excel.Workbook = excelApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
'Makes Excel invisible to the user until spreadsheet is populated
excelApp.Visible = False
With excelWorksheet
Dim i As Integer = 2
'Format cell headings
.Range("A1").Value = "First Name"
.Range("B1").Value = "Last Name"
.Range("C1").Value = "Address"
'Populate Excel spreadsheet
Try
.Range("A" & i.ToString).Value = "fname"
.Range("B" & i.ToString).Value = "lname"
.Range("C" & i.ToString).Value = "address"
i += 1
Catch ex As Exception
End Try
'Make Excel visible
excelApp.Visible = True
End With
End Sub