Dim xlObj As Object
Dim rs As DAO.Recordset
Dim j As Integer
Dim rowCnt As Integer
Dim curRow As Integer
Dim filePathName As String
Dim tabName As String
Dim db As Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Set db = CurrentDb
filePathName = Me!txtFolder & Me!txt_Title & Me!txt_Title_Ext
Set xlObj = CreateObject("Excel.application")
xlObj.Workbooks.Add
With xlObj
.Worksheets(1).Select
Set qdf = db.QueryDefs("qry_ExportRoster_Department_Staff_Sums3A")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenDynaset)
For j = 0 To rs.Fields.Count - 1
.Cells(1, j + 1).Value = rs(j).Name
Next
.Range("A2").CopyFromRecordset rs
rowCnt = .Worksheets(1).UsedRange.Rows.Count
Set qdf = db.QueryDefs("qry_ExportRoster_Department_Staff_Sums3")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rs = qdf.OpenRecordset(dbOpenDynaset)
For j = 0 To rs.Fields.Count - 1
.Cells(rowCnt + 3, j + 1).Value = rs(j).Name
Next
.Range("A" & rowCnt + 4).CopyFromRecordset rs
rowCnt = .Worksheets(1).UsedRange.Rows.Count
.Rows("1:1").RowHeight = 16
.Rows("5:5").RowHeight = 41
.Cells.Font.Name = "Arial"
.Cells.Font.Size = 10
.Range("A1:D1").Interior.ColorIndex = 15
.Range("A5:N5").Interior.ColorIndex = 15
.Rows("1:1").WrapText = True
.Rows("5:5").WrapText = True
.Columns("A").HorizontalAlignment = xlCenter
.Columns("B:C").HorizontalAlignment = xlLeft
.Columns("D:F").HorizontalAlignment = xlCenter
.Columns("G:J").HorizontalAlignment = xlRight
.Columns("K:M").HorizontalAlignment = xlCenter
.Columns("N").HorizontalAlignment = xlLeft
.Rows("1:1").HorizontalAlignment = xlCenter
.Rows("1:1").VerticalAlignment = xlCenter
.Rows("5:5").HorizontalAlignment = xlCenter
.Rows("5:5").VerticalAlignment = xlCenter
'Set Borders for 1st Row
With .Range("A1:D1").Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A1:D1").Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A1:D1").Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A1:D1").Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A1:D1").Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
'Set Borders for 5th Row
With .Range("A5:N5").Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A5:N5").Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A5:N5").Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A5:N5").Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A5:N5").Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
'Set Column Formats
.Columns("A").NumberFormat = "###0"
.Columns("D").NumberFormat = "###0"
.Columns("E:F").NumberFormat = "0.00"
.Columns("G:J").NumberFormat = "$#,##0.00"
.Columns("L").NumberFormat = "0.00"
.Columns("M").NumberFormat = "mm/dd/yyyy"
'Set Column Widths
.Columns("A").ColumnWidth = 11
.Columns("B").ColumnWidth = 33
.Columns("C").ColumnWidth = 25
.Columns("D").ColumnWidth = 12
.Columns("E:F").ColumnWidth = 10
.Columns("G:I").ColumnWidth = 14
.Columns("J:L").ColumnWidth = 10
.Columns("M").ColumnWidth = 11
.Columns("N").ColumnWidth = 24
.ActiveWorkbook.SaveAs filePathName
End With
xlObj.Quit
rs.Close
|