Word Table styles - buggy behaviour...
Hi all,
I have a bit of "unexpected behaviour" in Word (2003) I'm hoping to resolve with someone's help.
I have a template that uses a few table styles. All these Table styles have a 1pt border on the top and bottom of the whole table and one of them uses stripes (alternate 25% grey shading on the rows).
My first problem was that when applying a style from the task pane, the default behaviour was to have 'Apply special formats to:' switched on for first/last row/column. There doesn't seem to be a way of saving these preferences with the style. Is there a way of doing that???
I got round that by adding my styles to my custom toolbar and running this code: [VBA]With Selection.Tables(1)
'the style names match the button captions so it's one routine for all
.Style = Application.CommandBars.ActionControl.Caption
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = False
.ApplyStyleLastColumn = False
End With[/VBA]
Problem solved? No, I run this code from my tool bar and the border on the bottom of the table doesn't always appear. I can only make it appear by running the code and then pressing Ctrl+Y!!??? If run the code twice it still makes no difference.
Stumped :dunno
UPDATE: A workaround, rather than a solution
It would appear there is, in fact, no facility to save the ApplyStyleLastRow setting with your Table style, which is clearly an oversight.
After extensive testing, the only way to get the bottom border to apply is[VBA]SendKeys "^Y"[/VBA] (curiously Application.Repeat doesn't do it) which I'm not prepared to use in distrubuted code.
I decided to go with the flow on this and employ a workaround since it's obvious that it's a Word bug...
Since I only have two types of bottom border in use I'm jsut going to re-apply it and move on.[VBA]With Selection.Tables(1)
.Style = Application.CommandBars.ActionControl.Caption
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = False
.ApplyStyleLastColumn = False
With .Borders(wdBorderBottom)
.Visible = True
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth100pt
If Right(Application.CommandBars.ActionControl.Caption, 4) = "Grey" Then
.Color = wdColorGray25
Else
.Color = wdColorDarkRed
End If
End With
End With
[/VBA] It's a bit disappointing because I had high hopes for table styles. For a user to be able to apply a pre-defined format (that can be saved with the template rather than doing it all with code) to a table without effecting the paragraph styles they've chosen would clearly be a useful addition to Word if it worked reliably...
Thanks for the comments guys :thumb