0% found this document useful (0 votes)
54 views1 page

Pil As Excel

This function exports data from two recordsets (rs and rs2) to separate worksheets in a new Excel workbook. It copies the field names of each recordset to the first row and then copies the records below. It formats some columns, adjusts column widths, and makes the Excel application visible when complete.

Uploaded by

Troy Briggs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views1 page

Pil As Excel

This function exports data from two recordsets (rs and rs2) to separate worksheets in a new Excel workbook. It copies the field names of each recordset to the first row and then copies the records below. It formats some columns, adjusts column widths, and makes the Excel application visible when complete.

Uploaded by

Troy Briggs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Function ExportExcel(ByVal rs, rs2 As ADODB.

Recordset)
'Dim oExcel As Excel.Application
'Dim oWBook As Excel.Workbook
'Dim oSheet As Excel.Worksheet
Dim iFila As Long, iCol As Integer, i As Integer
Set oExcel = CreateObject("Excel.Application")
Set oWBook = oExcel.Workbooks.Add
Set oSheet = oWBook.Worksheets(1)
oSheet.Name = "ASIENTO"
Screen.MousePointer = vbHourglass
iFila = 1
iFila2 = 1
iCol2 = 1
iCol = 1
rs.MoveFirst
For i = 0 To rs.Fields.Count - 1
' pone el nombre de los campos en la primera fila
oSheet.Cells(iFila, i + 1) = rs.Fields(i).Name
Next
iFila = iFila + 1
With oSheet
' carga los registros del recordset
.Cells(iFila, iCol).CopyFromRecordset rs
oExcel.Columns(7).Select
oExcel.selection.NumberFormat = "#,##0.00"
oExcel.Columns(12).Select
oExcel.selection.NumberFormat = "0.00"
.Columns.AutoFit ' ajusta el ancho de las columnas
End With
Set oSheet = oWBook.Worksheets(2)
oSheet.Name = "OTROS"
rs2.MoveFirst
For i = 0 To rs2.Fields.Count - 1
' pone el nombre de los campos en la primera fila
oSheet.Cells(iFila2, i + 1) = rs2.Fields(i).Name
Next
iFila2 = iFila2 + 1
With oSheet
' carga los registros del recordset
.Cells(iFila2, iCol2).CopyFromRecordset rs2
.Columns.AutoFit 'ajusta el ancho de las columnas
End With
oExcel.Visible = True
Set oExcel = Nothing
Screen.MousePointer = vbDefault
End Function

You might also like