Sub Test_xlBorders(CaseNum)
'
' Demonstrates the use of xlBorders procedure
'
Dim OutLineWeight As String
Dim InLineWeight As String
Dim xlRange As Range
Select Case CaseNum
Case 0 'Out = none; In = none; Color = xlAutomatic
OutLineWeight = "none"
InLineWeight = "none"
Set xlRange = Range(Cells(1, 1), Cells(28, 10))
Call xlBorders(xlRange, OutLineWeight, InLineWeight)
Case 1 'Out = thick; In = thin; color = xlAutomatic
OutLineWeight = "thick"
InLineWeight = "thin"
Set xlRange = Range(Cells(2, 6), Cells(5, 10))
Call xlBorders(xlRange, OutLineWeight, InLineWeight)
Case 2 'Out = none; In = medium; color = red
OutLineWeight = "none"
InLineWeight = "medium"
Set xlRange = Range(Cells(7, 1), Cells(10, 5))
Call xlBorders(xlRange, OutLineWeight, InLineWeight, 3, 3)
Case 3 'Out = medium; In = hairline; color = blue
OutLineWeight = "medium"
InLineWeight = "hairline"
Set xlRange = Range(Cells(12, 3), Cells(18, 5))
Call xlBorders(xlRange, OutLineWeight, InLineWeight, 5, 5)
Case 4 'Out = thick; In = none
OutLineWeight = "thick"
InLineWeight = "none"
Set xlRange = Range(Cells(20, 1), Cells(21, 10))
Call xlBorders(xlRange, OutLineWeight, InLineWeight)
Case 5 'Out = thick/red; In = medium/blue
OutLineWeight = "thick"
InLineWeight = "medium"
Set xlRange = Range(Cells(23, 5), Cells(28, 10))
Call xlBorders(xlRange, OutLineWeight, InLineWeight, 3, 5)
Case Else
End Select
End Sub
Sub xlBorders(xlRange As Range, OutLineWeight As String, InLineWeight As String, _
Optional OutLineColor As Long = -4105, _
Optional InLineColor As Long = -4105)
'
'****************************************************************************************
' Function generates Inside and Outside borders for a target range
' Passed Values
' xlRange [in, range] target range
' OutLineWeight [in, string] weight of Outerior lines:
' hairline, thin, medium, thick, none
' InLineWeight [in, string] weight of Interior lines:
' hairline, thin, medium, thick, none
' OutLineColor [in, long, OPTIONAL] outside line color {default = xlAutomatic}
' InLineColor [in, long, OPTIONAL] inside line color {default = xlAutomatic}
'
'****************************************************************************************
'
'
Dim OutLineStyle As Variant
Dim OutLineWt As Variant
Dim InLineStyle As Variant
Dim InLineWt As Variant
OutLineStyle = xlContinuous
Select Case LCase(OutLineWeight)
Case "hairline"
OutLineWt = xlHairline
Case "thin"
OutLineWt = xlThin
Case "medium"
OutLineWt = xlMedium
Case "thick"
OutLineWt = xlThick
Case "none"
OutLineStyle = xlNone
Case Else
MsgBox "ERROR: bad value for OutLineWeight", _
vbCritical, "xlBorders"
Exit Sub
End Select
InLineStyle = xlContinuous
Select Case LCase(InLineWeight)
Case "hairline"
InLineWt = xlHairline
Case "thin"
InLineWt = xlThin
Case "medium"
InLineWt = xlMedium
Case "thick"
InLineWt = xlThick
Case "none"
InLineStyle = xlNone
Case Else
MsgBox "ERROR: bad value for InLineWeight", _
vbCritical, "xlBorders"
Exit Sub
End Select
On Error Resume Next
xlRange.Borders(xlDiagonalDown).LineStyle = xlNone
xlRange.Borders(xlDiagonalUp).LineStyle = xlNone
With xlRange.Borders(xlEdgeLeft)
.LineStyle = OutLineStyle
.Weight = OutLineWt
.ColorIndex = OutLineColor
End With
With xlRange.Borders(xlEdgeTop)
.LineStyle = OutLineStyle
.Weight = OutLineWt
.ColorIndex = OutLineColor
End With
With xlRange.Borders(xlEdgeBottom)
.LineStyle = OutLineStyle
.Weight = OutLineWt
.ColorIndex = OutLineColor
End With
With xlRange.Borders(xlEdgeRight)
.LineStyle = OutLineStyle
.Weight = OutLineWt
.ColorIndex = OutLineColor
End With
With xlRange.Borders(xlInsideVertical)
.LineStyle = InLineStyle
.Weight = InLineWt
.ColorIndex = InLineColor
End With
With xlRange.Borders(xlInsideHorizontal)
.LineStyle = InLineStyle
.Weight = InLineWt
.ColorIndex = InLineColor
End With
End Sub
Sub GridToggle()
'
' utility to toggle gridlines on and off
'
If ActiveWindow.DisplayGridlines = True Then
ActiveWindow.DisplayGridlines = False
Else
ActiveWindow.DisplayGridlines = True
End If
End Sub
|