To transfer data from Excel sheet to MSflexgrid in VB6.0
Code to transfer data from excel to Msflexgrid in Vb
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim fso As New FileSystemObject
Dim strxlsFileName As String
Dim i_RowCount As Integer, i_CurrentRow As Integer
Dim i_ColCount As Integer, i_CurrentCol As Integer
If g_txt_taskflowmodel.Text <> "" Then
strxlsFileName = g_txt_taskflowmodel
If Not fso.FileExists(strxlsFileName) Then
' Exit Sub
End If
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open(strxlsFileName)
Set xlSheet = xlBook.Sheets(1)
' i_RowCount = xlSheet.Rows.Count
i_CurrentRow = 1
Do
'While i_CurrentRow <= i_RowCount
MSFlexGrid1.Rows = i_CurrentRow
MSFlexGrid1.Row = i_CurrentRow - 1
i_CurrentCol = 1
If xlSheet.Cells(i_CurrentRow, 3) = "" Then
Exit Do
End If
Do
' While i_CurrentCol <= i_ColCount
If xlSheet.Cells(1, i_CurrentCol) = "" Then
Exit Do
End If
MSFlexGrid1.Col = i_CurrentCol - 1
MSFlexGrid1.Text = xlSheet.Cells(i_CurrentRow, i_CurrentCol)
i_CurrentCol = i_CurrentCol + 1
Loop
i_CurrentRow = i_CurrentRow + 1
Loop
Set xlSheet = Nothing
Set xlBook = Nothing
xlApp.Workbooks.Close
Set xlApp = Nothing
Else
MsgBox "Please enter the path of the Excel File", vbCritical, Excelfile
' On Error Resume Next
End If
Comments pls
Dim xlSheet As Excel.Worksheet
Dim fso As New FileSystemObject
Dim strxlsFileName As String
Dim i_RowCount As Integer, i_CurrentRow As Integer
Dim i_ColCount As Integer, i_CurrentCol As Integer
If g_txt_taskflowmodel.Text <> "" Then
strxlsFileName = g_txt_taskflowmodel
If Not fso.FileExists(strxlsFileName) Then
' Exit Sub
End If
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open(strxlsFileName)
Set xlSheet = xlBook.Sheets(1)
' i_RowCount = xlSheet.Rows.Count
i_CurrentRow = 1
Do
'While i_CurrentRow <= i_RowCount
MSFlexGrid1.Rows = i_CurrentRow
MSFlexGrid1.Row = i_CurrentRow - 1
i_CurrentCol = 1
If xlSheet.Cells(i_CurrentRow, 3) = "" Then
Exit Do
End If
Do
' While i_CurrentCol <= i_ColCount
If xlSheet.Cells(1, i_CurrentCol) = "" Then
Exit Do
End If
MSFlexGrid1.Col = i_CurrentCol - 1
MSFlexGrid1.Text = xlSheet.Cells(i_CurrentRow, i_CurrentCol)
i_CurrentCol = i_CurrentCol + 1
Loop
i_CurrentRow = i_CurrentRow + 1
Loop
Set xlSheet = Nothing
Set xlBook = Nothing
xlApp.Workbooks.Close
Set xlApp = Nothing
Else
MsgBox "Please enter the path of the Excel File", vbCritical, Excelfile
' On Error Resume Next
End If
Comments pls
Credits: Shreejith G
0 Comments:
Post a Comment
<< Home