save listview data to excel file

sigridish

Member
Joined
Nov 10, 2011
Messages
22
Programming Experience
Beginner
hello all! could someone help me on the loop part please?
here is my code

VB.NET:
Public Sub saveExcelFile(ByVal FileName As String)

        Dim Excel As Object

        Excel = CreateObject("Excel.Application")
        Excel.screenupdating = True
        Excel.Visible = True

        Dim xlWorkSheet As Object = Excel.workbooks.add
        [B]Excel.workbooks(1).worksheets(1).cells(1, 1).value = "Success"[/B]

        xlWorkSheet.SaveAs(FileName)

        Excel.quit()
        Excel = Nothing

    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim saveFileDialog1 As New SaveFileDialog
        saveFileDialog1.Filter = "Excel File|*.xlsx"
        saveFileDialog1.Title = "Save an Excel File"
        saveFileDialog1.ShowDialog()
        If saveFileDialog1.FileName <> "" Then
            saveExcelFile(saveFileDialog1.FileName)
        End If
    End Sub

the bold part must be changed cause everytime i open the saved file, word success is the data in there. i just copied this code. please help
 
Back
Top