Hola! Agradecería que alguien me dijera como hago para crear una hoja de Excell sencillita desde un programa en Visual Basic. Tengo esto, está sin pulir mucho pero es que no encuentro información al respecto y estoy muy perdida. Tal cual está, sale por el error de "no se puede abrir el libro" pero claro, es que creo que no está creada. Por favor, si alguien tiene algún ejemplo le agradecería que me lo enviara. Muchas gracias
Nuria
PD Esto pertenece a un módulo y se le llama desde un formulario. Se supone que tiene que escribir en una hoja excell una fila seleccionada en un listbox.
Dim xlApp As Excel.Application
Dim xlsHoja As Excel.Worksheet
Dim xlBook As Excel.Workbook
Dim xlsRango As Excel.Range
Dim xlsName As Excel.Name
Public Sub HojaExcell()
Dim Libro As String
Dim i As Integer
Libro = App.Path & "32" & ".xls"
If (xlApp Is Nothing) Then Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open(FileName:=Libro, readOnly:=False)
If Err <> 0 Then
MsgBox "No se puede abrir el libro " & Libro
Set xlBook = Nothing
Exit Sub
End If
Set xlsHoja = xlBook.Worksheets.Item("Config")
If Err <> 0 Then
MsgBox "Error en Impresión = " & Err
Exit Sub
End If
xlsHoja.Cells(1, 1).Value = "FECHA"
xlsHoja.Cells(1, 2).Value = "HORA"
If frmFormulario.ListBox.ListIndex <> -1 Then
xlsHoja.Cells(2, 1).Value = "01/01/05"
xlsHoja.Cells(2, 2).Value = "01:01:01"
End If
xlBook.Save
xlApp.Quit
Set xlApp = Nothing
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Open(FileName:=Libro, ReadOnly:=False)
If Err <> 0 Then
MsgBox "No se puede abrir el libro " & Libro
Set xlBook = Nothing
Set xlApp = Nothing
End If
xlApp.Visible = True
End Sub
[email protected]