Border Mystery?
I have code that copies border formatting from one cell to a range. Its
been working fine. But I'm now getting a runtime error "Unable to set the
Weight property of the Border class" trying to copy an xlInsideVertical
border. The same error occurs trying to copy the LineStyle property.
I know that a common problem with the xlInsideVertical border is that it can
only be applied to a multi-column range. My code checks for this condition.
However in this case, the target range is B20:E20.
I went back and retested this code under XL97, XL2000, XL2002 and XL2003
(all versions include all of the latest MS updates). It works under XL97
but fails under all of the later releases.
If I manually open the workbook under XL97 and then examine the source
cell's border in a watch window it has a LineStyle of 11 and a Weight
of -4138 (this is the case where the copy works). If I repeat this
procedure under XL2003, LineStyle is 241 and Weight is 225!
I presume this difference is what's causing it to work under XL97 and fail
under later versions.
I've looked at all of the LineStyle constants and neither 11 or 241 is
defined! I don't know what to make of that?
Here's the code in question:
Private Sub CopyBorder(borderType As Integer, Target As Range, source As
Range)
Dim TargetBorder As Border
Dim SourceBorder As Border
If Not (borderType = xlInsideHorizontal And Target.Rows.Count < 2 Or _
borderType = xlInsideVertical And Target.Columns.Count < 2)
Then
Set TargetBorder = Target.Borders(borderType)
Set SourceBorder = source.Borders(borderType)
TargetBorder.Weight = SourceBorder.Weight
TargetBorder.LineStyle = SourceBorder.LineStyle
TargetBorder.color = SourceBorder.color
TargetBorder.ColorIndex = SourceBorder.ColorIndex
End If
End Sub
Again, its the assignment of Weight and LineStyle that fail. The assignment
of Color and ColorIndex work fine.
Any thoughts?
TIA,
josh
|