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
.Range("A1") = "Roster Date:"
.Range("A2") = "Department:"
.Range("A3") = "Department ID:"
.Range("A4") = "SpeedType:"
.Range("A5") = "Budgeted FTE:"
.Range("A6") = "Budgeted Salaries:"
.Range("A7") = "Funds Available:"
.Range("B1") = DLookup("[rosterDate]", "qry_ExportRoster_Department_Staff_Sums3A")
.Range("B2") = DLookup("[department]", "qry_ExportRoster_Department_Staff_Sums3A")
.Range("B3") = DLookup("[departmentID]", "qry_ExportRoster_Department_Staff_Sums3A")
.Range("B4") = DLookup("[speedtype]", "qry_ExportRoster_Department_Staff_Sums3A")
.Range("B5") = DLookup("[budgetedFTE]", "qry_ExportRoster_Department_Staff_Sums3A")
.Range("B6") = DLookup("[budget]", "qry_ExportRoster_Department_Staff_Sums3A")
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 + 2, j + 1).Value = rs(j).Name
Next
.Range("A" & rowCnt + 3).CopyFromRecordset rs
rowCnt = .Worksheets(1).UsedRange.Rows.Count
'Sum Columns
.Range("E" & rowCnt + 1 & "").Formula = "=Sum(" & "E10:E" & rowCnt & " )"
.Range("F" & rowCnt + 1 & "").Formula = "=Sum(" & "F10:F" & rowCnt & " )"
.Range("G" & rowCnt + 1 & "").Formula = "=Sum(" & "G10:G" & rowCnt & " )"
.Range("H" & rowCnt + 1 & "").Formula = "=Sum(" & "H10:H" & rowCnt & " )"
.Range("B7").Formula = "=B6-Sum(" & "G10:G" & rowCnt & " )"
'Formatting
.Rows("1:" & rowCnt + 1).RowHeight = 20
.Rows("9:9").RowHeight = 50
.Cells.Font.Name = "Arial"
.Cells.Font.Size = 12
.Range("A9:N9").Interior.ColorIndex = 15
.Rows("1:1").WrapText = True
.Rows("9:9").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
.Range("A1:A7").HorizontalAlignment = xlLeft
.Rows("9:9").HorizontalAlignment = xlCenter
.Rows("1:" & rowCnt + 1).VerticalAlignment = xlCenter
'Set Borders for 9th Row
With .Range("A9:N9").Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A9:N9").Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A9:N9").Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A9:N9").Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A9:N9").Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A9:N" & rowCnt + 1).Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Range("A9:N" & rowCnt).Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With .Range("A9:N" & rowCnt).Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With .Range("A9:N" & rowCnt).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
With .Range("A9:N" & rowCnt).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
.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"
.Range("B5").NumberFormat = "0.00"
'Set Column Widths
.Columns("A").ColumnWidth = 20
.Columns("B").ColumnWidth = 33
.Columns("C").ColumnWidth = 35
.Columns("D").ColumnWidth = 12
.Columns("E:F").ColumnWidth = 10
.Columns("G:H").ColumnWidth = 17
.Columns("I").ColumnWidth = 14
.Columns("J:L").ColumnWidth = 10
.Columns("M").ColumnWidth = 16
.Columns("N").ColumnWidth = 24
With xlObj
.Sheets("Sheet1").Select
.Sheets("Sheet1").Name = .Range("B2").Value
.Sheets("Sheet2").Select
.ActiveWindow.SelectedSheets.Delete
.Sheets("Sheet3").Select
.ActiveWindow.SelectedSheets.Delete
.ActiveWindow.Zoom = 80
End With
'Required to turn off PageSetup.Zoom so FitToPagesWide and FitToPagesTall work
xlObj.ActiveSheet.PageSetup.Zoom = False
With xlObj.ActiveSheet.PageSetup
.LeftMargin = xlObj.Application.InchesToPoints(0.5)
.RightMargin = xlObj.Application.InchesToPoints(0.5)
.TopMargin = xlObj.Application.InchesToPoints(0.5)
.BottomMargin = xlObj.Application.InchesToPoints(0.5)
.HeaderMargin = xlObj.Application.InchesToPoints(0.5)
.FooterMargin = xlObj.Application.InchesToPoints(0.5)
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintArea = "$A:$N"
End With
.ActiveWorkbook.SaveAs filePathName
End With
'Set xlObj = Nothing
xlObj.Quit
rs.Close
|