Sub Test_xlBorders(CaseNum)
Dim OutLineWeight As String
Dim InLineWeight As String
Dim xlRange As Range
Select Case CaseNum
Case 0
OutLineWeight = "none"
InLineWeight = "none"
Set xlRange = Range(Cells(1, 1), Cells(28, 10))
Call xlBorders(xlRange, OutLineWeight, InLineWeight)
Case 1
OutLineWeight = "thick"
InLineWeight = "thin"
Set xlRange = Range(Cells(2, 6), Cells(5, 10))
Call xlBorders(xlRange, OutLineWeight, InLineWeight)
Case 2
OutLineWeight = "none"
InLineWeight = "medium"
Set xlRange = Range(Cells(7, 1), Cells(10, 5))
Call xlBorders(xlRange, OutLineWeight, InLineWeight, 3, 3)
Case 3
OutLineWeight = "medium"
InLineWeight = "hairline"
Set xlRange = Range(Cells(12, 3), Cells(18, 5))
Call xlBorders(xlRange, OutLineWeight, InLineWeight, 5, 5)
Case 4
OutLineWeight = "thick"
InLineWeight = "none"
Set xlRange = Range(Cells(20, 1), Cells(21, 10))
Call xlBorders(xlRange, OutLineWeight, InLineWeight)
Case 5
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)
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()
If ActiveWindow.DisplayGridlines = True Then
ActiveWindow.DisplayGridlines = False
Else
ActiveWindow.DisplayGridlines = True
End If
End Sub
|