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 / May 2008

Tip: Looking for answers? Try searching our database.

COMException when editing range and HRESULT: 0x80010105

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
joniba - 05 May 2008 09:36 GMT
Hi all, I'm not sure if this is the right place to post this, but:

I am trying to work with the PIA for microsoft word from VS2008, framework
3.5.  I am working in a class library with a reference to the Office 12 PIA.  
I have Office 2003 (only) installed.

 I am getting a lot of exceptions I do not understand and I cannot find
documentation to explain, so any help would be greatly appreciated (as well
as documentation, if anyone knows of any).

First, trying to edit a range is always throwing an exception, whether it in
this format (I'm just pasting some of the relevant lines from the code):

oTable = doc.Tables[iTable]
oRange = oTable.Rows[iRow].Cells[3].Range;
oRange.Text = ""; // exception thrown here

Or if the last line is written like this instead:

object count = oRange.Characters.Count;
object charUnit = WdUnits.wdCharacter;
oRange.Delete(ref charUnit , ref count);  // throws exception

In the second case the exception message is:

"Cannot edit Range."

In the first case I get HRESULT: 0x80010105 exception where the code stack
shows that the exception occurred in "set_Range" method in the RPC server.

Here are two more examples that return this same HRESULT: 0x80010105:

The last line in this code that is working with a Document word object
(called "doc") throws an exception:

Range oRange = doc.Content;
oRange.Find.ClearFormatting();
oRange.Find.MatchWildcards = true;
oRange.Find.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;     // throws exception

The following line also throws an exception:

oTable.Cell(iSide1Row, 2).Range.Text = strOriginal;

Where I've checked that both "strOriginal" and "oTable.Cell(iSide1Row,
2).Range.Text" evaluate to proper strings.

Tell me if you need to see more code.
Jean-Guy Marcil - 05 May 2008 13:20 GMT
> Hi all, I'm not sure if this is the right place to post this, but:
>
[quoted text clipped - 43 lines]
> Where I've checked that both "strOriginal" and "oTable.Cell(iSide1Row,
> 2).Range.Text" evaluate to proper strings.

I have not worked with VS2008, but it seems to me that the errors you get
are probabaly caused by your code trying to act on obejcts the code cannot
modify.

For example, you have a few examples involving table cells. All table cells
include a cell marker "¤". This marker cannot be removed or replaced. If your
code is trying to delete such a marker, you may have problems. Try making
sure that the cell marker (always the last character in a cell range) is not
part of your range objects.

Also, "oRange.Delete(ref charUnit , ref count)" will delete whatever (ref
charUnit , ref count) represents. If oRange is not collapsed, oRange will be
deleted as well. You either need to collapse oRange to the end, or need to
debug your code and see exactly what range you are trying to delete. For
example, you cannot delete the last ¶ in the document, ¶'s before or after
tables may be problematic... But, really, it seems that you are setting "ref
charUnit , ref count" to be exaclty whatever oRange is, why not just use
"oRange.Delete()" instead of the 3 lines of code you have?

I am not sure why you are getting an error with the Find part, but try using
constant values intead of constant names... For instance,
"wdAlignParagraphCenter" is 1. So, try:
  oRange.Find.ParagraphFormat.Alignment = 1
joniba - 06 May 2008 14:38 GMT
Hello Marcil, thanks for the quick response,
"Reply" doesn't seem to work in these forums when logged in with my account,
so I am using a friend's.

Responses inline:

> I have not worked with VS2008, but it seems to me that the errors you get
> are probabaly caused by your code trying to act on obejcts the code cannot
[quoted text clipped - 5 lines]
> sure that the cell marker (always the last character in a cell range) is not
> part of your range objects.

I have checked the value of Range.Text before trying to set it to
string.Empty.  The value is always a short text followed by "\r\a".  I'm
assuming that's not the symbol you mean.  I tried deleting all but the last
character and still the same error.

> Also, "oRange.Delete(ref charUnit , ref count)" will delete whatever (ref
> charUnit , ref count) represents. If oRange is not collapsed, oRange will be
[quoted text clipped - 4 lines]
> charUnit , ref count" to be exaclty whatever oRange is, why not just use
> "oRange.Delete()" instead of the 3 lines of code you have?

There is no other overload method available to me.  Trying to call Delete()
without parameters doesn't compile.  

> I am not sure why you are getting an error with the Find part, but try using
> constant values intead of constant names... For instance,
> "wdAlignParagraphCenter" is 1. So, try:
>    oRange.Find.ParagraphFormat.Alignment = 1

Setting the Alignment to an int value as you suggest doesn't compile (no
implicit conversion exists etc. etc.).

I'd really appreciate any other suggestions, because if I cannot get around
these seemingly small problems I will have at least 3 weeks of code-rewriting
to do (to use a different interface than Word for what I need).
joniba - 11 May 2008 15:01 GMT
In case anyone else has had this problem, by absolute luck we discovered
that adding:

oRange.Select();

Before the:

oRange.Text = "";

Fixes that part of the bizarre problem.

Now I just need to figure out why

oRange.Find.ParagraphFormat.Alignment =
WdParagraphAlignment.wdAlignParagraphCenter;

> Hello Marcil, thanks for the quick response,
> "Reply" doesn't seem to work in these forums when logged in with my account,
[quoted text clipped - 40 lines]
> these seemingly small problems I will have at least 3 weeks of code-rewriting
> to do (to use a different interface than Word for what I need).
Jean-Guy Marcil - 13 May 2008 13:51 GMT
> In case anyone else has had this problem, by absolute luck we discovered
> that adding:
[quoted text clipped - 6 lines]
>
> Fixes that part of the bizarre problem.

I guess that this is a C# problem because the following code works as
expected in VBA:

Dim doc As Document
Dim oTable As Table
Dim oRange As Range
Dim iRow As Long

Set doc = ActiveDocument
iRow = 2

Set oTable = doc.Tables(1)
Set oRange = oTable.Rows(iRow).Cells(3).Range
oRange.Text = ""
 
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.