PDA

View Full Version : Word Table styles - buggy behaviour...



Killian
03-10-2005, 08:59 AM
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: 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
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

TonyJollans
03-10-2005, 10:44 AM
Hi Killian,

The consensus, as far as I can tell, is that Table Styles are a nice idea, but that they are not yet ready for serious use. I know Gerry (fumei) loves them but he is about the only person I've found with much good to say about them.

There is an element of conflict, and more than a little confusion, in the way Table Styles sit with the 'old' AutoFormats, and that seems to come into play with the various ApplyStyle properties. Contrary to the Help files, and the Macro Recorder, they really don't work.

I don't think they are really meant to be used with Styles. When you think about it, selecting which elements of a style you want to apply isn't what you do with paragraph styles, so why should it work with table styles? Set the style up the way you want and apply it is about the best answer I can come up with.

fumei
03-10-2005, 01:38 PM
No of course not. When you play with PARTS of a style, then it is not that style any more.

Help on this matter lies. Their example does not work.

I too have tried individual .ApplyStyle_whatever = whatever (True or False), and it does not work as advertised. So, sure, in one sense Tony, you are correct. They are still a bit buggy. However, I do not alter Styles on the fly. I design styles as solid objects.

Killian
03-11-2005, 03:53 AM
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 isSendKeys "^Y" (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.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
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