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 / September 2007

Tip: Looking for answers? Try searching our database.

Odd Table add problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Omatase - 19 Sep 2007 04:59 GMT
I'm writing some code against the Word object model to add a table to
some word documents. I have tens of thousands of these files that need
these tables added to them. Here is some code that shows me adding the
table as well as setting some properties on the table to adjust how it
looks:

Range tableLocation = aDoc.Range(ref start, ref start);
theTable = aDoc.Tables.Add(tableLocation, 1, 3, ref missingValue, ref
autofitBehavior);

theTable.LeftPadding = 0.0f;
theTable.RightPadding = 0.0f;

// eliminate table borders
theTable.Borders.Enable = 0;

Every once in a while (it appears to be random) I get en error thrown
on this line:

theTable.LeftPadding = 0.0f;

The error is:

The server threw an exception. (Exception from HRESULT: 0x80010105
(RPC_E_SERVERFAULT))

I don't get this error consistently. I can run the same code on the
same document immediately after the failure and it works. Can anyone
help with this?
Shauna Kelly - 23 Sep 2007 00:43 GMT
Hi Omatase

> I can run the same code on the
>same document immediately after the failure and it works.

I have experience similar things with tables, though not particulary with
.LeftPadding that I recall. Setting the width of a table is often precarious
and so is setting borders. When I run into problems like these with tables I
generally create a little loop and if it errors out I'll give it, say, 3
times to get it right. Otherwise, just move on.

For what it's worth, I find that reading a setting is reliable. So if it's a
really important setting, you can read the property after you try to set it,
and, if necesary, warn the user that it hasn't "stuck".

Hope this helps.

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

> I'm writing some code against the Word object model to add a table to
> some word documents. I have tens of thousands of these files that need
[quoted text clipped - 25 lines]
> same document immediately after the failure and it works. Can anyone
> help with this?
 
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.