| re: MS Excel ---> <----Visual BAsic Pl Help!!!!!
hai,
you can do this by using ado connection which establish aconnection between vb and excel. below i have given excel connection string . so using you insert and reterive data as like you access database. code
Public Function pblfnOpenExcelRecordset(ByVal sFile As String, ByVal strQuery As String) As ADODB.Recordset
On Error GoTo ErrorHandler
Dim rsExcel As ADODB.Recordset
Dim sconn As String
Set rsExcel = New ADODB.Recordset
With rsExcel
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockBatchOptimistic
End With
sconn = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & sFile & "; ReadOnly=False;"
rsExcel.Open strQuery, sconn
Set rsExcel.ActiveConnection = Nothing
Set pblfnOpenExcelRecordset = rsExcel
Exit Function
ErrorHandler:
Debug.Print Err.Description + " " + _
Err.Source, vbCritical, "Import"
Err.Clear
End Function
code
|