Como abrir un archivo de excel en un formulario de visual
Hola, alguien sabe como abrir un archivo de excel en un formulario de Visual Basic y sacar los campos de las celdas,alguien podria decirme como, gracias
a mi me prestaro este ejemplo espero que te sirva
Private Sub Command1_Click()
generaHoja
End
End Sub
Sub generaHoja()
Dim e As Object
Dim ruta As String
On Error GoTo error1
Set e = CreateObject("Excel.Application")
ruta = App.Path & "\ejemplo.xls"
e.Workbooks.Open ruta
e.Visible = True
e.ActiveSheet.Range("A1:B1").Select
e.ActiveCell = "Hola Caracola"
e.ActiveWorkbook.Save
e.Application.Quit
Set e = Nothing
Exit Sub
\'ERROR
error1:
MsgBox Err.Description
e.Application.Quit
Set e = Nothing
End Sub
Private Sub Command2_Click()
leeHoja
End
End Sub
Sub leeHoja()
Dim e As Object
Dim ruta As String
On Error GoTo error1
Set e = CreateObject("Excel.Application")
ruta = App.Path & "\ejemplo.xls"
e.Workbooks.Open ruta
e.Visible = True
e.ActiveSheet.Range("A1:B1").Select
MsgBox e.ActiveCell
e.ActiveWorkbook.Save
e.Application.Quit
Set e = Nothing
Exit Sub
\'ERROR
error1:
MsgBox Err.Description
e.Application.Quit
Set e = Nothing
End Sub
Private Sub Command1_Click()
generaHoja
End
End Sub
Sub generaHoja()
Dim e As Object
Dim ruta As String
On Error GoTo error1
Set e = CreateObject("Excel.Application")
ruta = App.Path & "\ejemplo.xls"
e.Workbooks.Open ruta
e.Visible = True
e.ActiveSheet.Range("A1:B1").Select
e.ActiveCell = "Hola Caracola"
e.ActiveWorkbook.Save
e.Application.Quit
Set e = Nothing
Exit Sub
\'ERROR
error1:
MsgBox Err.Description
e.Application.Quit
Set e = Nothing
End Sub
Private Sub Command2_Click()
leeHoja
End
End Sub
Sub leeHoja()
Dim e As Object
Dim ruta As String
On Error GoTo error1
Set e = CreateObject("Excel.Application")
ruta = App.Path & "\ejemplo.xls"
e.Workbooks.Open ruta
e.Visible = True
e.ActiveSheet.Range("A1:B1").Select
MsgBox e.ActiveCell
e.ActiveWorkbook.Save
e.Application.Quit
Set e = Nothing
Exit Sub
\'ERROR
error1:
MsgBox Err.Description
e.Application.Quit
Set e = Nothing
End Sub
