Ver Mensaje Individual
  #2 (permalink)  
Antiguo 10/07/2004, 10:20
Renegado
 
Fecha de Ingreso: febrero-2002
Ubicación: Santiago
Mensajes: 253
Antigüedad: 23 años, 3 meses
Puntos: 0
Si muestras los Datos en un ListView puedes utilizar esta función:

Public Sub Genera_Excel(Lista As ListView, Nombre As String)
Dim Aplicacion As Excel.Application
Dim Libro As Excel.Workbook
Dim Planilla As Excel.Worksheet
Dim i As Long
Dim j As Integer
Dim Mensaje As String
Load frmSABAvance
frmSABAvance.Show
frmSABAvance.ProgressBar1.Min = 0
frmSABAvance.ProgressBar1.Max = Lista.ListItems.Count

' el control debe ser un listview
On Error GoTo error
Set Aplicacion = New Excel.Application
Set Libro = Aplicacion.Workbooks.Add
Set Planilla = Libro.Worksheets(1)
On Error GoTo 0
On Error Resume Next
'Libro.Worksheets(2).Delete
'Libro.Worksheets(2).Delete
On Error GoTo 0
' GENERACIÓN PLANILLA
For i = 0 To Lista.ListItems.Count
frmSABAvance.ProgressBar1.Value = i
For j = 0 To Lista.ColumnHeaders.Count - 1
If i = 0 Then
Planilla.Cells(i + 1, j + 1) = Trim(Lista.ColumnHeaders(j + 1).Text)
Else
If j = 0 Then
Planilla.Cells(i + 1, j + 1) = Lista.ListItems(i).Text
Else
Planilla.Cells(i + 1, j + 1) = Lista.ListItems(i).SubItems(j)
End If
End If
Next
Next
Planilla.Range("A1").Select
Unload frmSABAvance
Nombre = InputBox("Nombre de la planilla a generar", "Generación de Planilla", Nombre)
If Nombre <> "" Then
On Error GoTo Salir
Planilla.SaveAs FileName:=Nombre
Mensaje = Mensaje & Libro.Path & "\" & Libro.Name & vbCrLf
MsgBox "Se generó una planilla" & vbCrLf & Mensaje
End If
Salir:
Aplicacion.Quit
Set Aplicacion = Nothing
Set Libro = Nothing
Set Planilla = Nothing
Exit Sub
error:
MsgBox "se genero un error " & vbCrLf & Err.Description, vbCritical, "Mensaje del Sistema"
Unload frmSABAvance
Exit Sub
End Sub


Declarala en un modúlo.
Para llamarla agrega esto en un command button

Private Sub Command1_Click()
'Envia ListView1 a Excel
If ListView1.ListItems.Count = 0 Then
MsgBox "No hay datos para procesar en Excel", vbInformation, "Mensaje del Sistema"
Else
Genera_Excel Me.ListView1, "Nombre Archivo"
End If
End Sub


Esta función toma el encabezado y el Detalle del Listview y lo traspasa a excel