Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Modifying Table Style via VBA - does not retain settings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ArchieDog - 18 Jun 2007 10:22 GMT
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
Shauna Kelly - 18 Jun 2007 14:03 GMT
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

> Hi All
>
[quoted text clipped - 39 lines]
> Many thanks.
> ArchieDog
Archie Dog - 19 Jun 2007 08:06 GMT
Thanks, Shauna.  Very informative - think I will leave those well alone.

>Hi
>
[quoted text clipped - 20 lines]
>> Many thanks.
>> ArchieDog

Signature

ArchieD

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.