Public Sub Excel_This(sQuery As String, sExcelFileName As String)
On Error GoTo Err_This
' Dim xlapp As excel.Application
' Dim wb As excel.workbook
' Dim ws As excel.worksheet
Dim xlapp As Object
Dim xlBook As Object
Dim xlSheet As Object
Dim rs As DAO.Recordset
Dim LastR As Long
Set xlapp = CreateObject("Excel.Application")
Set xlBook = xlapp.Workbooks.Open(sExcelFileName)
Set xlSheet = xlBook.Worksheets(1)
Set rs = CurrentDb.OpenRecordset(sQuery)
With xlSheet
.Range("2:" & .Rows.Count).Delete
.Range("A2").copyfromrecordset rs
LastR = .Cells(.Rows.Count, "ae").End(-4162).Row ' xlUp = -4162
.Range("ae" & LastR + 2) = "=SUM(AE2:AE" & LastR & ")"
End With
xlapp.Visible = True
'
' Set xlSheet = Nothing
' Set xlBook = Nothing
' Set xlapp = Nothing
Exit_This:
Exit Sub
Err_This:
Call Error_Action(Err, Err.description, "modECdatabases @ Excel_This", Erl())
Err = 0
Resume Exit_This
End Sub
|