Private Sub Command2_Click()
Dim fso As Object
Dim strNombreLibro As String
Dim appExcel As Object
' creo una nueva instancia a Excel
Set appExcel = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
strNombreLibro = Text1
' me aseguro de la existencia de la hoja de calculo
If Not fso.FileExists(strNombreLibro) Then
MsgBox "El libro " & strNombreLibro & " no existe.", vbCritical
Exit Sub
End If
' abro el libro
appExcel.Workbooks.Open (strNombreLibro)
appExcel.Sheets("Hoja1").Activate
With appExcel
.Cells(1, 1).Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Activate
Loop
.ActiveCell.FormulaR1C1 = Text2
.ActiveCell.Offset(0, 1).Activate
.ActiveCell.FormulaR1C1 = Text3
.ActiveCell.Offset(0, 1).Activate
.ActiveCell.FormulaR1C1 = Text4
End With
' guardo (en este caso no le veo necesidad de guardar si solo has leido una
celda)
appExcel.ActiveWorkbook.Save
' cierro la instancia a excel
appExcel.Quit
' elimino objetos
Set fso = Nothing
Set appExcel = Nothing
End Sub
Leer las respuestas