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 / Tables / October 2004

Tip: Looking for answers? Try searching our database.

Getting the format of a table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mystery Man - 06 Jul 2004 03:23 GMT
I have a situation where I create a table programmatically. I now want
to set the format of this table based on another table.

I have code similar to the following:

object oformat = (object)oldTable.AutoFormatType;
newTable.AutoFormat(ref oformat, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing);

As you can see, getting the format type of the old table is easy
enough. But how do I get the other properties, ie Apply Border, Apply
Shading, Apply Font etc from the oldTable? (These are the parameters
to the AutoFormat method).

Eg something like oldTable.Format.ApplyBorder  

NB: I cannot copy and paste the table, and then write cell by cell as
this has performance implications. Therefore, I create the table
contents in text, convert the text to a table and then I want to
simply get the table format from the old table to apply it to the new
table.
Cindy M  -WordMVP- - 07 Jul 2004 18:23 GMT
Hi Mystery,

Version of Word?

From what I can see, you'd need to apply the AutoFormat, then compare
the settings of the two tables. Then apply the AutoFormat again with
these settings.

Since you're having to do this, may one assume this is a document a user
will have been working with? What guarantee do you have the user won't
have made manual adjustments to the auto formatting?

> I have a situation where I create a table programmatically. I now want
> to set the format of this table based on another table.
[quoted text clipped - 19 lines]
> simply get the table format from the old table to apply it to the new
> table.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
Mystery Man - 08 Jul 2004 12:05 GMT
Thanks Cindy

The version of Word is 2000 and above.

How can I compare the settings of these two tables programmatically.
If I had access to these properties, then all would be solved.

No, the user does not modify the document. This happens all behinds
the scene. The user is simply presented with the end result.

> Hi Mystery,
>
[quoted text clipped - 39 lines]
> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)
Cindy M  -WordMVP- - 09 Jul 2004 09:58 GMT
Hi Mystery,

> The version of Word is 2000 and above.
>  
That precludes using Table Styles, then.

> How can I compare the settings of these two tables programmatically.
> If I had access to these properties, then all would be solved.
>  
You have the original table you want to match; you have the second
table formatted with the "default" AutoFormat. You compare each of the
possible things that could be affected and see if they match. If they
don't, the option was different.

If the borders are different, then ApplyBorders must have been "false"
when the original table was formatted. If the font formatting of the
first columns is different (bold vs. non-bold, usually), then
ApplyFirstColumn was "false" for the original table. Etc.

> No, the user does not modify the document. This happens all behinds
> the scene. The user is simply presented with the end result.

If that's the case, then why don't you already know what AutoFormat
was used on the original table?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
Mystery Man - 10 Jul 2004 14:04 GMT
Thanks Cindy

> You have the original table you want to match; you have the second
> table formatted with the "default" AutoFormat. You compare each of the
> possible things that could be affected and see if they match. If they
> don't, the option was different.

I apolgise if its a really dumb question, but how do I programatically
get access to the following properties in the original table:

ApplyBorders
ApplyShading
ApplyFont
ApplyColor
ApplyHeadingRows
ApplyLastRow
ApplyFirstColumn
ApplyLastColumn
AutoFit

I have checked the object model and no property is obvious to me.

The property AutoFormatType simply returns a WdTableFormat. This would
only be the first parameter in the call to the AutoFormat method when
setting up the new table.

Thanks for your patience

> Hi Mystery,
>
[quoted text clipped - 28 lines]
> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)
Mystery Man - 25 Jul 2004 12:06 GMT
Hi Cindy (or anyone else)

Sorry to keep asking, but how do I programatically get access to the
following properties in a table:

ApplyBorders
ApplyShading
ApplyFont
ApplyColor
ApplyHeadingRows
ApplyLastRow
ApplyFirstColumn
ApplyLastColumn
AutoFit

I have checked the object model and no property is obvious to me.

Thanks

> Thanks Cindy
>
[quoted text clipped - 56 lines]
> > This reply is posted in the Newsgroup; please post any follow question
> > or reply in the newsgroup and not by e-mail :-)
Shauna Kelly - 25 Jul 2004 13:16 GMT
Hi Mystery Man

The macro recorder is very useful for learning about this kind of thing.
Tools > Macros > Record New Macro. Try inserting and formatting a table, and
then inspect the code that Word creates.

In particular, look for code like the following:

   With Selection.Tables(1)
       With .Borders(wdBorderLeft)
           .LineStyle = wdLineStyleSingle
           .LineWidth = wdLineWidth050pt
           .Color = wdColorAutomatic
       End With
   End With

Hope this helps.

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

> Hi Cindy (or anyone else)
>
[quoted text clipped - 75 lines]
> > > This reply is posted in the Newsgroup; please post any follow question
> > > or reply in the newsgroup and not by e-mail :-)
Cindy M  -WordMVP- - 18 Aug 2004 11:12 GMT
Hi Mystery,

> Sorry to keep asking

I apologize: "real life" took me away from the groups for
quite a while...

> do I programatically get access to the
> following properties in a table:

You can't access what was applied or not applied using
AutoFormat (although I'd think that, since you
programmatically insert all the tables you'd KNOW that, and
could save the information somewhere to look up later).

But what you can do is compare the actual formatting of the
existing table and see if it matches the formatting of a
table inserted with all the defaults. Does it have the same
border colors? Same shading? Same font formattting? If not,
then the first was inserted with that aspect set to
"False".

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:-)
Kind writer/user/programmer - 29 Oct 2004 02:52 GMT
Thanks for the helpful suggestions of defining table behaviour with VBA.

I've been experimenting with the TableAutoFormat and discovered contention
between style definitions and Table AutoFormat definitions.  

This new feature (Table Autoformat) bulldozes over styles. Thus, if I've set
the header row with a Table Heading style defined as bold centered text, when
I apply the TableTemplate, the first row bold setting in the TableAutoFormat
toggles this attribute to <not bold>.

Reveal formatting is willy-nilly:

TableFormat defines the paragraph alignment as left. The paragraph style is
defined as centered. Its centered. TableFormat defines the font style as
Arial. But I can't get the Bold to stick.

Selecting Clear Formatting in the Reveal Formatting pane (when the table is
selected), formats all the cells to be the selected Table style- I can't get
a paragraph or character style to display, but the paragaphs jump to 6 points
above and below--I presume based on Normal paragraph style.  I didn't set
paragraph spacing in the Table AutoFormat, yet it pulled one out of somewhere.

How to erase/squelch/remove Table AutoFormat from a table? I can figure out
table to text, text to table--I want to know where to find--and alter-- the
hidden attributes for an entire table?  Reveal all formatting doesn't permit
me to delete the table's AutoFormat setting--and "clear formatting" defaults
to  the AutoFormat which has hidden controls for paragraph spacing, special
character formatting (i.e., <empahsis> on certain words).
 
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.