by Chaudhary Pradeep Kr Roy (6 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 29th November 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code can be used to read an MS-EXCEL file. U need to select the Excel File and the sheet name, and u can manupulate it as if it is a
API Declarations
'\ Put Three Command Button "cmdClose" and "CmdReadData" and "cmdBrow"
Commonduialog Box named "cdlgBrow"
Tow Text Box named "txtFileName" and "TxtSheetName"
Public gSConn As New ADODB.Connection '\ Source Connection
Public sDBName As String, sUID As String, sPWD As String
Dim rs As New ADODB.Recordset
cdlgBrow.InitDir = App.Path
cdlgBrow.ShowOpen
If cdlgBrow.FileName <> "" Then
txtFileName = Trim(cdlgBrow.FileName)
End If
End Sub
Private Sub CmdReadData_Click()
Me.MousePointer = vbHourglass
On Error GoTo ErrHand
Dim ctr As Double
Dim strIns As String, sConnStr As String
Dim dblTotRow As Integer
'\\ Connecting to Source
sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Trim(txtFileName) & ";Extended Properties=Excel 8.0"
gSConn.Open sConnStr
'\\ Opening Recordset
strsql = "SELECT * FROM [" & txtSheetname & "$]"
rs.Open strsql, gSConn, adOpenStatic
dblTotRow = rs.RecordCount
For i = 1 To dblTotRow
' this point onwards u can proceed like a normal recordset manupulation
For j = 0 To rs.Field.Count
Debug.Print rs.Fields(j).Value
Next j
Debug.Print vbCrLf
rs.MoveNext
Next
Me.MousePointer = vbDefault
Exit Sub
ErrHand:
MsgBox Err.Description, vbInformation, "upload Error"
Me.MousePointer = vbDefault
Err.Clear
End Sub
No comments have been posted about This code can be used to read an MS-EXCEL file. U need to select the Excel File and the sheet name,. Why not be the first to post a comment about This code can be used to read an MS-EXCEL file. U need to select the Excel File and the sheet name,.