alktrigger
Aimless Extraordinaire
- Local time
- Today, 06:37
- Joined
- Jun 9, 2009
- Messages
- 124
I'm using the following code to export a set of queries into an excel report. What do i need to add in to have a variable count the number of records I export so that I can add standard fields at the end of the excel sheet?
Code:
Public Function ExportReportDumpSummary()
Dim strWorksheet As String
Dim strWorksheetPath As String
Dim appExcel As Excel.Application
Dim sht As Excel.Worksheet
Dim wkb As Excel.Workbook
Dim rng As Excel.Range
Dim strTable As String
Dim strRange As String
Dim strSaveName As String
Dim strPrompt As String
Dim strTitle As String
Dim strDefault As String
'On Error GoTo ErrorHandler
'Re-create table for export:
strTable = "tblReportDump2"
'DoCmd.SetWarnings False
'DoCmd.OpenQuery "qmakAccountSummary"
'Create worksheet save name:
strWorksheetPath = "C:\RMU\" 'GetWorksheetsPath()"
strWorksheet = "DS_Ships"
strSaveName = strWorksheetPath & strWorksheet & ".xls"
Debug.Print "Worksheet; Save; Name; " & strSaveName; ""
On Error Resume Next
'Delete existing worksheet (if there is one):
Kill strSaveName
'On Error GoTo ErrorHandler
'Export query data to a new worksheet in Excel 9 format:
DoCmd.TransferSpreadsheet transfertype:=acExport, _
spreadsheettype:=acSpreadsheetTypeExcel9, _
TableName:=strTable, FileName:=strSaveName, _
hasfieldnames:=True
'Open the newly created worksheet and insert title material:
Set appExcel = GetObject(, "Excel.Application")
appExcel.Workbooks.Open (strSaveName)
Set wkb = appExcel.ActiveWorkbook
Set sht = appExcel.ActiveSheet
sht.Activate
With sht
'Remove the "ID" column
.Columns("A:A").Delete Shift:=xlToLeft
.Columns("P:P").Delete Shift:=xlToLeft
'Apply the Calibri 10 pt font to the entire worksheet:
.Range("A:O").Font.Name = "Arial"
.Range("A:O").Font.Size = 10
'change column Widths
.Range("A:A").ColumnWidth = 45
.Range("B:B").ColumnWidth = 10
.Range("C:C").ColumnWidth = 10
.Range("D:L").ColumnWidth = 2.6