AYUDA POR FAVOR NECESITO EXPORTAR A EXCEL
Publicado por RAUL (17 intervenciones) el 06/10/2006 14:53:59
Hola a todos espero que me puedan ayudar tengo unos datos en tabla y necesito exportarlo a excel lo cual lo conseguido, pero el problema es como lo hago para que se vayan creando las hojas en la planilla, hoja1 con sus dato hoja2 con sus dato hoja3 con su datos, etc , solo lo he conseguido para la primera NO SE COMO CAMBIAR DE HOJA DE CALCULO Y ME PUEDE CREAR LO OTROS DATOS, ADJUNTO EL CODIGO. PARA CREAR UNA HOJA
Private Sub Boton_Exporta_Click()
Dim xx As Integer
Dim nFila As Integer
On Error GoTo ErrorExcel
Dim objExcel As Excel.Application
Set objExcel = New Excel.Application
objExcel.Visible = True
objExcel.SheetsInNewWorkbook = 2
objExcel.Workbooks.Add
With objExcel.ActiveSheet
.Cells(2, 2) = "ESTADISTICA "
.Range(.Cells(2, 2), .Cells(2, 24)).HorizontalAlignment = xlHAlignCenterAcrossSelection
With .Cells(2, 2).Font
.Color = vbBlue
.Size = 14
.Bold = True
End With
For xx = 1 To 2
.Cells(nFila, 2) = "Meses"
.Cells(nFila, 3) = "Total"
.Cells(nFila, 4) = "Total"
.Cells(nFila, 5) = "Total"
.Range(.Cells(nFila, 3), .Cells(nFila, 5)).HorizontalAlignment = xlHAlignCenterAcrossSelection
nFila = 22
Next
.Columns("A").ColumnWidth = 2.5
.Columns("B").ColumnWidth = 6
End With
cSql = "SELECT * FROM bceramic WHERE cer_tipo ='C' and cer_vtamt2='V' ORDER BY cer_tipo,cer_vtamt2,cer_mes;"
Set rss = con.Execute(cSql)
Do While rss.EOF = False
nFila = 6 + Val(rss!cer_mes)
With objExcel.ActiveSheet
.Cells(nFila, 3) = 0 + rss!cer_nrobol
.Cells(nFila, 4) = 0 + rss!cer_nrofac
.Cells(nFila, 5) = 0 + (rss!cer_nrobol + rss!cer_nrofac)
.Cells(nFila, 7) = 0 + rss!cer_piso1
.Cells(nFila, 8) = 0 + rss!cer_piso2
.Cells(nFila, 9) = 0 + rss!cer_piso3
.Cells(nFila, 10) = 0 + rss!cer_piso4
.Cells(nFila, 11) = 0 + rss!cer_piso5
End With
rss.MoveNext
Loop
end sub
esto el codigo como creo oactivo la siguiente hojas
Private Sub Boton_Exporta_Click()
Dim xx As Integer
Dim nFila As Integer
On Error GoTo ErrorExcel
Dim objExcel As Excel.Application
Set objExcel = New Excel.Application
objExcel.Visible = True
objExcel.SheetsInNewWorkbook = 2
objExcel.Workbooks.Add
With objExcel.ActiveSheet
.Cells(2, 2) = "ESTADISTICA "
.Range(.Cells(2, 2), .Cells(2, 24)).HorizontalAlignment = xlHAlignCenterAcrossSelection
With .Cells(2, 2).Font
.Color = vbBlue
.Size = 14
.Bold = True
End With
For xx = 1 To 2
.Cells(nFila, 2) = "Meses"
.Cells(nFila, 3) = "Total"
.Cells(nFila, 4) = "Total"
.Cells(nFila, 5) = "Total"
.Range(.Cells(nFila, 3), .Cells(nFila, 5)).HorizontalAlignment = xlHAlignCenterAcrossSelection
nFila = 22
Next
.Columns("A").ColumnWidth = 2.5
.Columns("B").ColumnWidth = 6
End With
cSql = "SELECT * FROM bceramic WHERE cer_tipo ='C' and cer_vtamt2='V' ORDER BY cer_tipo,cer_vtamt2,cer_mes;"
Set rss = con.Execute(cSql)
Do While rss.EOF = False
nFila = 6 + Val(rss!cer_mes)
With objExcel.ActiveSheet
.Cells(nFila, 3) = 0 + rss!cer_nrobol
.Cells(nFila, 4) = 0 + rss!cer_nrofac
.Cells(nFila, 5) = 0 + (rss!cer_nrobol + rss!cer_nrofac)
.Cells(nFila, 7) = 0 + rss!cer_piso1
.Cells(nFila, 8) = 0 + rss!cer_piso2
.Cells(nFila, 9) = 0 + rss!cer_piso3
.Cells(nFila, 10) = 0 + rss!cer_piso4
.Cells(nFila, 11) = 0 + rss!cer_piso5
End With
rss.MoveNext
Loop
end sub
esto el codigo como creo oactivo la siguiente hojas
Valora esta pregunta


0