Hi All,
Having some trouble figuring out how to automate conditional formatting of an excel spreadsheet after having output it from my database.
I have cobbled together some code that effectively exports the query to Excel and applies some of the formatting (i.e. column width, row height, hides column C) I copied from a recorded macro, but when it comes to highlighting rows where the day name is "Saturday" or "Sunday" I get nothing. When I close the spreadsheet I see an access error message saying "invalid call or argument"... I'm guessing that is a clue to what I am doing wrong.
My code is...
Private Sub Command592_Click()
Dim xl As Object
Set xl = CreateObject("Excel.Application")
xl.Application.ScreenUpdating = False
xl.Visible = True
xl.Application.ScreenUpdating = True
On Error GoTo Command592_Click_Err
DoCmd.OutputTo acOutputQuery, "qryRC2_CheckedOnly_Crosstab", "ExcelWorkbook(*.xlsx)", "C:\temp\Resource_Chart2.xlsx", False, "", , acExportQualityScreen
xl.Workbooks.Open ("C:\temp\Resource_Chart2.xlsx")
xl.Cells.Select
xl.Selection.ColumnWidth = 35
xl.Selection.RowHeight = 15
xl.Range("A:A,B:B").Select
xl.Range("B1").Activate
xl.Range("A:A,B:B").EntireColumn.AutoFit
xl.Columns("C:C").Select
xl.Selection.EntireColumn.Hidden = True
xl.Cells.Select
xl.Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=if($B1=""Saturday"",True,if($B1=""Sunday"",True, False))"
xl.Selection.FormatConditions(Selection.FormatCond itions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent2
.TintAndShade = 0.799981688894314
End With
xl.Selection.FormatConditions(1).StopIfTrue = False
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
xl.Rows("1:1").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
xl.Range("D2").Select
xl.ActiveWindow.FreezePanes = True
Command592_Click_Exit:
Exit Sub
Command592_Click_Err:
MsgBox Error$
Resume Command592_Click_Exit
End Sub
Any ideas? Suggestions?
Regards,
Mitch