Hi Everyone

I'm trying to create a piece of VBA code that will apply
preset cell shading and border formatting to either a
single cell or a group of selected cells, see below code:

Sub BlueCell()

With Selection.Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = RGB(200, 225, 250)
End With

Options.DefaultBorderLineStyle = wdLineStyleSingle
Options.DefaultBorderColor = RGB(0, 125, 200)
Options.DefaultBorderLineWidth = wdLineWidth050pt

With Selection.Borders
.OutsideLineStyle = Options.DefaultBorderLineStyle
.OutsideLineWidth = Options.DefaultBorderLineWidth
.OutsideColor = Options.DefaultBorderColor
End With

For Each Border In Selection.Borders
If Border.Inside = True Then
Border.LineStyle = Options.DefaultBorderLineStyle
Border.LineWidth = Options.DefaultBorderLineWidth
Border.Color = Options.DefaultBorderColor
End If
Next Border
End Sub


What I'm finding is that the codes works fine if I have
more than one table cell selected however, if I have a
single cell selected the code falls over within the IF...
Then... Else... statement at the:

Border.LineWidth = Options.DefaultBorderLineWidth


Can anyone help?

Big thank you in advance

Al

Re: Table Cell Formatting via VBA by Klaus

Klaus
Thu Feb 19 14:28:47 CST 2004

Hi Alex,

Looks like a bug to me:
With a single cell selected, there should be no inside borders, but
Selection.Borders.Count is still 8 (top, left, bottom, right, inside
horízontal and vertical, 2 diagonal).

As a work-around, you could use
If Border.Inside = True And Selection.Cells.Count > 1 Then

Greetings,
Klaus



Re: Table Cell Formatting via VBA by Alex

Alex
Thu Feb 19 16:22:06 CST 2004

Hi Klaus

That worked a treat.


I assuming that you are the same Klaus Linke as mentioned=20
on 'ListNumbering Street, Revisited'.

I'd just like to say on behalf of all us long suffering=20
Word users, excellent work.

Many thanks

Alex


>-----Original Message-----
>Hi Alex,
>
>Looks like a bug to me:
>With a single cell selected, there should be no inside=20
borders, but
>Selection.Borders.Count is still 8 (top, left, bottom,=20
right, inside
>hor=EDzontal and vertical, 2 diagonal).
>
>As a work-around, you could use
> If Border.Inside =3D True And Selection.Cells.Count > 1=20
Then
>
>Greetings,
>Klaus
>
>
>.
>