Sub export()
'name spreadsheet for object reference
Dim ExcelSheet As Object
'name string vars for dir and spreadsheet file name
Dim savename As String
'Add reference to Excel library
Call XLLibrary
'get path info
savename = inputbox("Where would youlike to save?")
'transfer qryXL to file 'savename', closes file
'DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "YourQuery/Table", Savename, True
'opens new file
Workbooks.Open Filename:=savename
'set object 'savename'(excel spreadsheet) for action
Set ExcelSheet = Workbooks.Application.ActiveWorkbook
'these are just some random formatting examples
With ExcelSheet
.Application.Visible = True
.Sheets(1).Range("A1:E1").Font.Bold = True
.Sheets(1).Columns("A:A").Columns.AutoFit
.Sheets(1).Columns("B:B").Columns.AutoFit
With Sheets(1)
With Columns("C:C").Columns
.AutoFit
.HorizontalAlignment = xlRight
.NumberFormat = "#,##0"
.Range("C1:E1").HorizontalAlignment = xlCenter
End With
With Columns("D:D").Columns
.AutoFit
.HorizontalAlignment = xlRight
.NumberFormat = "#,##0"
End With
With Columns("E:E").Columns
.AutoFit
.HorizontalAlignment = xlRight
.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="0"
.FormatConditions(1).Font.ColorIndex = 2
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="0"
.FormatConditions(2).Font.ColorIndex = 3
End With
Range("A1:E1").FormatConditions.Delete
Range("C1:E1").HorizontalAlignment = xlCenter
End With
.Save
.Quit
End With
End Sub
Sub XLLibrary()
'Add reference to Excel library
On Error Resume Next
Application.References.AddFromGuid "{00020813-0000-0000-C000-000000000046}", 2, 3
End Sub