Monday, October 4, 2010

Retrieving data from an excel through Database connection

FileName = "C:\Book1.xls"
SheetName = "Sheet1"
vValue = "Murali"

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & FileName & ";" & "Extended Properties=""Excel 8.0;HDR=Yes;"";"
strQuery="update [" & SheetName & "$] Set "
strQuery=strQuery & "Country='" & "',"
strQuery=strQuery & "City='" & "'"
strQuery=strQuery & " where Name ='" & vValue &"'"
msgbox strQuery
objRecordset.Open strQuery , objConnection, 3, 3, 1
'Close
objConnection.Close
Set objRecordSet = Nothing

No comments:

Post a Comment