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?

Re: Odd Table add problem by Shauna

Shauna
Sat Sep 22 18:43:48 CDT 2007

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


"Omatase" <Omatase@gmail.com> wrote in message
news:1190174359.102859.233100@d55g2000hsg.googlegroups.com...
> 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?
>