Private Sub CmdRateCardExport_Click()
'On Error GoTo Err_CmdRateCardExport_Click
Dim CMS As String
Dim Site As String
Dim x As Integer
Dim y As Integer
Dim j As Long
Dim k As Long
Dim objexcelapp As Excel.Application
Dim objexcelwb As Excel.Workbook
CMS = Forms!frmratecardentry!CboCMSRef
Site = Forms!frmratecardentry!cboSite
'Delete existing RateCard.xls file
If Dir("C:\data\Projects\RateCard.xls") <> "" Then
Kill ("C:\data\Projects\RateCard.xls")
Else
'Export QryRateCardExport from Rate Card Database
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "QryRateCardExport", "C:\data\Projects\RateCard.xls", True, CMS & "-" & Site
Set objexcelapp = New Excel.Application
Set objexcelwb = objexcelapp.Workbooks.Open _
("C:\data\Projects\RateCard.xls")
objexcelapp.Visible = True
'Insert 4 rows
objexcelapp.Rows("1:1").Select
objexcelapp.Selection.Insert shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
objexcelapp.Selection.Insert shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
objexcelapp.Selection.Insert shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
objexcelapp.Selection.Insert shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
'Insert 2 columns
objexcelapp.Columns("A:A").Select
objexcelapp.Selection.Insert shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
objexcelapp.Selection.Insert shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
'Copy Contract # & Site to header
objexcelapp.Range("C5").Select
objexcelapp.Selection.copy
objexcelapp.Range("A2").Select
objexcelapp.activesheet.paste
objexcelapp.Application.CutCopyMode = False
objexcelapp.Range("D5").Select
objexcelapp.Selection.copy
objexcelapp.Range("A3").Select
objexcelapp.activesheet.paste
objexcelapp.Application.CutCopyMode = False
objexcelapp.Range("C6").Select
objexcelapp.Selection.copy
objexcelapp.Range("E2").Select
objexcelapp.activesheet.paste
objexcelapp.Application.CutCopyMode = False
objexcelapp.Range("D6").Select
objexcelapp.Selection.copy
objexcelapp.Range("E3").Select
objexcelapp.activesheet.paste
objexcelapp.Application.CutCopyMode = False
'Delete Contract # and site columns
objexcelapp.Columns("B:D").Select
objexcelapp.Selection.Delete shift:=xlToLeft
'Delete RateCardType Heading
objexcelapp.Range("b5").Clear
'Make headings bold
objexcelapp.Range("A2:B3").Select
objexcelapp.Selection.Font.Bold = True
objexcelapp.Selection.Font.ColorIndex = 2
objexcelapp.Rows("5:5").Select
objexcelapp.Selection.Font.Bold = True
objexcelapp.Selection.Font.ColorIndex = 2
j = objexcelapp.WorksheetFunction.CountIf(Columns("B:B"), "Core Fleet")
k = objexcelapp.WorksheetFunction.CountIf(Columns("B:B"), "As Required")
'Centre UM & Rate
objexcelapp.Columns("d:e").Select
With objexcelapp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'Color background Blue
objexcelapp.Cells.Select
With objexcelapp.Selection
.Interior.Color = 12611584
.Font.Name = "arial"
End With
'Colour table background yellow & white
x = 2
For y = 6 To (j + k + 5)
objexcelapp.Cells(y, x).Select
With objexcelapp.Selection
.Interior.ColorIndex = 1
.Font.ColorIndex = 2
End With
objexcelapp.Cells(y, x + 1).Select
With objexcelapp.Selection
.Interior.ColorIndex = 36
End With
objexcelapp.Cells(y, x + 2).Select
With objexcelapp.Selection
.Interior.ColorIndex = 2
End With
objexcelapp.Cells(y, x + 3).Select
With objexcelapp.Selection
.Interior.ColorIndex = 2
End With
Next y
'Colour headings black
objexcelapp.Range("A2:B3").Select
With objexcelapp.Selection
.Interior.ColorIndex = 1
End With
objexcelapp.Range("B5:E5").Select
With objexcelapp.Selection
.Interior.ColorIndex = 1
End With
objexcelapp.Range("B6:E6").Offset(j, 0).Select
objexcelapp.Selection.Insert shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
objexcelapp.Range("B6:E6").Offset(j, 0).Select
With objexcelapp.Selection
.Interior.Color = 12611584
End With
'Borders
objexcelapp.Range("A2:B3").Select
objexcelapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
objexcelapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With objexcelapp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Color = -16776961
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = -16776961
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = -16776961
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Color = -16776961
.TintAndShade = 0
.Weight = xlMedium
End With
objexcelapp.Range("B5:E5").Resize(j + 1, 4).Select
objexcelapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
objexcelapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With objexcelapp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Color = 1
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = 1
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = 1
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Color = 1
.TintAndShade = 0
.Weight = xlMedium
End With
objexcelapp.Range("b5:e5").Offset(j + 2, 0).Select
objexcelapp.Selection.Resize(k, 4).Select
objexcelapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
objexcelapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With objexcelapp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Color = 1
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = 1
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = 1
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Color = 1
.TintAndShade = 0
.Weight = xlMedium
End With
'Column Borders
objexcelapp.Range("B5").Resize(j + 1, 1).Select
objexcelapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
objexcelapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With objexcelapp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
objexcelapp.Selection.Borders(xlInsideVertical).LineStyle = xlNone
objexcelapp.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
objexcelapp.Selection.Offset(0, 1).Select
objexcelapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
objexcelapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With objexcelapp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With objexcelapp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
objexcelapp.Selection.Borders(xlInsideVertical).LineStyle = xlNone
objexcelapp.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
objexcelapp.Selection.Offset(0, 1).Select
objexcelapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
objexcelapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With objexcelapp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With objexcelapp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
objexcelapp.Selection.Borders(xlInsideVertical).LineStyle = xlNone
objexcelapp.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
objexcelapp.Range("B5:e5").Offset(j + 2, 0).Select
objexcelapp.Selection.Resize(k, 1).Select
objexcelapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
objexcelapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With objexcelapp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
objexcelapp.Selection.Borders(xlInsideVertical).LineStyle = xlNone
objexcelapp.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
objexcelapp.Selection.Offset(0, 1).Select
objexcelapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
objexcelapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With objexcelapp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With objexcelapp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
objexcelapp.Selection.Borders(xlInsideVertical).LineStyle = xlNone
objexcelapp.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
objexcelapp.Selection.Offset(0, 1).Select
objexcelapp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
objexcelapp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With objexcelapp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With objexcelapp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = -16777215
.TintAndShade = 0
.Weight = xlMedium
End With
With objexcelapp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
objexcelapp.Selection.Borders(xlInsideVertical).LineStyle = xlNone
objexcelapp.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
'Merge Rate Card Type
objexcelapp.Range("B6").Resize(j, 1).Select
With objexcelapp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
objexcelapp.Selection.Merge
With objexcelapp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
objexcelapp.Selection.Font.Bold = True
objexcelapp.Range("B6").Offset(2, 0).Select
objexcelapp.Selection.Resize(k, 1).Select
With objexcelapp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
objexcelapp.Selection.Merge
With objexcelapp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
objexcelapp.Selection.Font.Bold = True
'Change rate to currency
objexcelapp.Range("e6").Resize(j, 1).Select
objexcelapp.Selection.Style = "Currency"
objexcelapp.Range("e6").Offset(j + 1).Select
objexcelapp.Selection.Resize(k, 1).Select
objexcelapp.Selection.Style = "Currency"
objexcelapp.Columns("A:E").entirecolumn.AutoFit
objexcelapp.UserControl = True
Set objexcelapp = Nothing
End If
'Exit_CmdRateCardExport_Click:
' Exit Sub
'Err_CmdRateCardExport_Click:
' MsgBox Err.Description
' Resume Exit_CmdRateCardExport_Click
End Sub