BillDickenson
IS-IT--Management
I am trying for format some excel from Access and i keep having trouble with the formatting commands. So I have two questions...
Periodically, someone suggests inserting the number code instead of the defined constants. Where do I look that up ?
And; does anyone see what I'm going wrong here. It fails in the line below the comment "the next line fails". Thanks
Public Function FormatSRCSummary()
Dim iFilename As String
Dim szQueryName As String
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object
If gszWorksheetPath = "" Then
Call GlobalLoad
End If
iFilename = gszWorksheetPath & "SRC Summary.XLS"
szQueryName = "qTotalBNPbyMonth"
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If TypeName(xlApp) = "Nothing" Then
'Excel was not open
Set xlApp = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set xlWB = xlApp.WorkBooks.Open(iFilename)
Set xlWS = xlWB.Worksheets(szQueryName)
With xlWS.Range("E:E,F:F,H:H,I:I,K:K,L:L,N:N,O:O,R:R,Q:Q,T:T,U:U,X:X,Y:Y,AA:AA,AB:AB,AC:AC,AD:AD,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP:AP")
.Select
.FormatConditions.Delete
'The next line fails
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="0"
.FormatConditions(1).Interior.ColorIndex = 6
End With
With xlWS.Range("G:G,J:J,M:M,P
,S:S,V:V,Y:Y,AB:AB,AE:AE,AH:AH,AK:AK,AN:AN,AQ:AQ")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="0"
.FormatConditions(1).Interior.ColorIndex = 3
.Interior.ColorIndex = 15
End With
xlWS.Columns("E:AQ").NUMBERFORMAT = "$#,##0_);($#,##0)"
With xlWS.Rows("1:1").Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
xlWS.Range("A1:AQ16").Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(5, 6, 7, 8, _
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 _
, 36, 37, 38, 39, 40, 41, 42, 43), Replace:=True, PageBreaks:=False, _
SummaryBelowData:=True
xlWS.Columns("A:AQ").EntireColumn.AutoFit
With xlWB
.SaveAs iFilename
.Close SaveChanges:=True
End With
Set xlWB = Nothing
xlApp.Quit
Set xlApp = Nothing
End Function
Periodically, someone suggests inserting the number code instead of the defined constants. Where do I look that up ?
And; does anyone see what I'm going wrong here. It fails in the line below the comment "the next line fails". Thanks
Public Function FormatSRCSummary()
Dim iFilename As String
Dim szQueryName As String
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object
If gszWorksheetPath = "" Then
Call GlobalLoad
End If
iFilename = gszWorksheetPath & "SRC Summary.XLS"
szQueryName = "qTotalBNPbyMonth"
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If TypeName(xlApp) = "Nothing" Then
'Excel was not open
Set xlApp = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set xlWB = xlApp.WorkBooks.Open(iFilename)
Set xlWS = xlWB.Worksheets(szQueryName)
With xlWS.Range("E:E,F:F,H:H,I:I,K:K,L:L,N:N,O:O,R:R,Q:Q,T:T,U:U,X:X,Y:Y,AA:AA,AB:AB,AC:AC,AD:AD,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP:AP")
.Select
.FormatConditions.Delete
'The next line fails
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="0"
.FormatConditions(1).Interior.ColorIndex = 6
End With
With xlWS.Range("G:G,J:J,M:M,P
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="0"
.FormatConditions(1).Interior.ColorIndex = 3
.Interior.ColorIndex = 15
End With
xlWS.Columns("E:AQ").NUMBERFORMAT = "$#,##0_);($#,##0)"
With xlWS.Rows("1:1").Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
xlWS.Range("A1:AQ16").Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(5, 6, 7, 8, _
9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 _
, 36, 37, 38, 39, 40, 41, 42, 43), Replace:=True, PageBreaks:=False, _
SummaryBelowData:=True
xlWS.Columns("A:AQ").EntireColumn.AutoFit
With xlWB
.SaveAs iFilename
.Close SaveChanges:=True
End With
Set xlWB = Nothing
xlApp.Quit
Set xlApp = Nothing
End Function