Tenia pensado utilizar la siguinte funcion pero me he dado cuenta que cuando tengo un rs.filter="campo='50'" pues simplemente lo ignora y me exportar todo el recordset completo.
Public Function Export_sExcel(rec As Recordset) As Boolean
On Error GoTo errSub
Dim Excel As Object
Dim Libro As Object
Dim Hoja As Object
Dim arrData As Variant
Dim iRec As Long
Dim iCol As Integer
Dim iRow As Integer
Screen.MousePointer = 11
' -- Crear los objetos para utilizar el Excel
Set Excel = CreateObject("Excel.Application")
Set Libro = Excel.Workbooks.Add
' -- Hacer referencia a la hoja
Set Hoja = Libro.Worksheets(1)
Excel.Visible = True: Excel.UserControl = True
Hoja.Cells(1, 1).Value = "Titulo"
iCol = rec.Fields.Count
For iCol = 1 To rec.Fields.Count
Hoja.Cells(3, iCol).Value = rec.Fields(iCol - 1).Name
Next
If Val(Mid(Excel.Version, 1, InStr(1, Excel.Version, ".") - 1)) > 8 Then
Hoja.Cells(4, 1).CopyFromRecordset rec
Else
'arrData = rec.GetRows
'iRec = UBound(arrData, 2) + 1 'ubound devuelve el subindice mas alto
'For iCol = 0 To rec.Fields.Count - 1 'recordset de 0 a 3 osea 4 campos
'For iRow = 0 To iRec - 1
'If IsDate(arrData(iCol, iRow)) Then
'arrData(iCol, iRow) = Format(arrData(iCol, iRow))
'ElseIf IsArray(arrData(iCol, iRow)) Then
'arrData(iCol, iRow) = "Array Field"
'End If
'Next iRow
'Next iCol
' -- Traspasa los datos a la hoja de Excel
'Hoja.Cells(2, 1).Resize(iRec, rec.Fields.Count).Value = GetData(arrData)
End If
Excel.selection.CurrentRegion.Columns.AutoFit
Excel.selection.CurrentRegion.Rows.AutoFit
'Hoja.Name = ""
'Libro.saveAs App.Path & "\libro"
'Libro.Close
Set Hoja = Nothing
Set Libro = Nothing
Set Excel = Nothing
Export_sExcel = True
Screen.MousePointer = 0
Exit Function
errSub:
MsgBox Err.Description, vbCritical, "Error"
Export_sExcel = False
Screen.MousePointer = 0
End Function
Private Function GetData(vValue As Variant) As Variant
Dim X As Long, Y As Long, xMax As Long, yMax As Long, T As Variant
xMax = UBound(vValue, 2): yMax = UBound(vValue, 1)
ReDim T(xMax, yMax)
For X = 0 To xMax
For Y = 0 To yMax
T(X, Y) = vValue(Y, X)
Next Y
Next X
GetData = T
End Function