by Rahul Sardesai And Irshad Barot (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 19th August 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
A Simple Code To Convert Your Data From ListView Control To Microsoft Excel File....
API Declarations
1. Project -> Components -> Microsoft Windows Common Dialog Control
Name it as cmnDlgs
2. Project -> Refernce -> Microsoft EXCEL 8.0/9.0 Object Library
3. ListView Control....
Name is as lvwCCC
4. Progress Bar....
Name it as barProgress
'
On Error GoTo myError
'
With cmnDlgs
.InitDir = App.Path
.DefaultExt = "*.xls"
.Filter = "Microsoft Excel File | *.xls"
.ShowSave
End With
'
barProgress.Min = 0
barProgress.Max = lvwCCC.ListItems.Count
'
barProgress.Value = 0
'
barProgress.Visible = True
'
Dim objXL As New Excel.Application
Dim intRow As Integer
Dim intCol As Integer
'
objXL.Workbooks.Add
objXL.Worksheets.Add
'
objXL.DisplayAlerts = False
objXL.Visible = False
'
For intCtr = 1 To lvwCCC.ColumnHeaders.Count Step 1
objXL.ActiveCell(1, intCtr) = "'" & UCase(lvwCCC.ColumnHeaders(intCtr).Text)
objXL.ActiveCell(1, intCtr).Font.Bold = True
Next intCtr
'
For intRow = 1 To lvwCCC.ListItems.Count Step 1
objXL.ActiveCell(intRow + 1, 1) = "'" & lvwCCC.ListItems(intRow).Text
For intCol = 1 To lvwCCC.ColumnHeaders.Count - 1 Step 1
objXL.ActiveCell(intRow + 1, intCol + 1) = "'" & lvwCCC.ListItems(intRow).SubItems(intCol)
Next intCol
barProgress.Value = intRow
Next intRow
'
objXL.ActiveSheet.Name = "Warning Bulletin"
'
For intCtr = objXL.Worksheets.Count To 1 Step -1
If objXL.Worksheets(intCtr).Name <> "Warning Bulletin" Then
objXL.Worksheets(intCtr).Delete
End If
Next intCtr
'
objXL.ActiveWorkbook.SaveAs (cmnDlgs.FileName)
objXL.ActiveWorkbook.Close
'
MsgBox "View exported to EXCEL file successfully...."
'
Set objXL = Nothing
'
barProgress.Visible = False
'
myError:
'
If Err.Number <> 0 Then
MsgBox Err.Description, , "Error"
Exit Sub
End If
'
End Sub
No comments have been posted about A Simple Code To Convert Your Data From ListView Control To Microsoft Excel File..... Why not be the first to post a comment about A Simple Code To Convert Your Data From ListView Control To Microsoft Excel File.....