RE:URGE!! Abrir documento excel desde VB
declaras los objetos ADO
Dim CN As New ADODB.Connection
Dim rsOrdenes As New ADODB.Recordset
Private Sub Abrir_conexion()
On Error GoTo ErrHandler
Set CN = New ADODB.Connection
' -- connection provider
CN.Provider = "Microsoft.Jet.OLEDB.4.0"
'--- create the connection to Excel File
'--- notice for the "Extended Property"
'--- for Excel 97/2000/2002 use Excel 8.0
'--- for Excel 95 use Excel 5.0
CN.ConnectionString = _
"Data Source= G:\ORDEN\Ordenes.xls;" & _
"Extended Properties=Excel 8.0;"
CN.CursorLocation = adUseClient
CN.Open
' EL RECORSET
Set rsOrdenes = New ADODB.Recordset
'--- aBRE EL recordset
'--- "HOJA1" ES EL NOMBRE DE UNA DE LAS HOJAS
'--- DEL ARCHIVO DE EXCEL
rsOrdenes.Open "SELECT * FROM [HOJA1$] ", CN, adOpenDynamic, adLockOptimistic
Set MSHFlexGrid1.DataSource = rsOrdenes
Exit Sub
ErrHandler:
MsgBox "No puedo establecer una conexion. Verifique la conexion o el formato del archivo de Excel en G:\ORDENES"
End Sub