> 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 = ""