Modifying Table Style via VBA - does not retain settings

  • Thread starter ArchieDog via OfficeKB.com
  • Start date
A

ArchieDog via OfficeKB.com

Hi All

I am trying to modify a table style using the code below:

Sub Set_Padding()
Dim styTable As Style

Set styTable = ActiveDocument.Styles("My Table Style")

With styTable.Table
.TopPadding = InchesToPoints(0.08)
.BottomPadding = InchesToPoints(0.08)
.LeftPadding = InchesToPoints(0.08)
.RightPadding = InchesToPoints(0.08)
End With

End Sub

If I create a table based on the specific table style (My Table Style) the
table looks as I want it to - the code appears to have worked. However, if I
go into the style's properties (as though intending to modify it), or if I
look at the table's properties (Tables, Table Properties, Options) the
default cell margins have not changed - it remains at whatever was set before
the code was run.

If I run the code again to make further changes - e.g. change the values for
the cell padding - eventually it all goes very, very wrong indeed with the
table appearance changing to something not asked for and the style/table
properties for default cell margins never changing.

The code appears to work in that the end result is as required but I need it
to correctly update the style's properties.

Can anyone tell me what I'm missing, please? I'm sure it must be something
obvious. By the way, I am using Word 2003 SP2.

Many thanks.
ArchieDog
 
S

Shauna Kelly

Hi

Table styles never seem to work quite as you expect. I find they are
moderately more reliable if I explicitly set a table style to be based on
"Table Normal" like this:

Set styTable = ActiveDocument.Styles("My Table Style")
styTable.BaseStyle = ActiveDocument.Styles("Table Normal").NameLocal

And, make sure you have appropriate font sizes for your Normal style and
your table style as described at
Why I don't use Custom Table Styles in Microsoft Word 2002 and 2003
http://www.ShaunaKelly.com/word/tablestyles/index.html

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
A

Archie Dog via OfficeKB.com

Thanks, Shauna. Very informative - think I will leave those well alone.

Shauna said:
Hi

Table styles never seem to work quite as you expect. I find they are
moderately more reliable if I explicitly set a table style to be based on
"Table Normal" like this:

Set styTable = ActiveDocument.Styles("My Table Style")
styTable.BaseStyle = ActiveDocument.Styles("Table Normal").NameLocal

And, make sure you have appropriate font sizes for your Normal style and
your table style as described at
Why I don't use Custom Table Styles in Microsoft Word 2002 and 2003
http://www.ShaunaKelly.com/word/tablestyles/index.html

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
[quoted text clipped - 39 lines]
Many thanks.
ArchieDog
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top