Exception adding a field at the end of a row

D

David Thielen

Hi;

This happens only if I try to add a field outside a table at the end of a
row (not in the cell, but outside the table after row 0 of a 2x3 table.

The code is:
object fieldType = WdFieldType.wdFieldAutoTextList;
object fieldText = "\"" + "<:forEach>" + "\"" + " \\t \"" +
"</wr:forEach>".Replace("\"", "\\\"") + "\"";
object preserveFormatting = false;
// note rng.Start = rng.End = 3 - get it from Selection
Field fld = app.ThisDocument.Fields.Add(rng, ref fieldType, ref fieldText,
ref preserveFormatting);

The error is:
System.Runtime.InteropServices.COMException occurred
HelpLink="C:\\Program Files\\Microsoft
Office\\Office12\\1033\\WDMAIN11.CHM#37373"
Message="This command is not available."
Source="Microsoft Word"
ErrorCode=-2146823683
StackTrace:
at Microsoft.Office.Interop.Word.Fields.Add(Range Range, Object&
Type, Object& Text, Object& PreserveFormatting)
at net.windward.autotag.word.WordDocument.WriteTag(TagLocation tag)
in
C:\src\kahuna\AutoTag\AutoTag2007\net\windward\autotag\word\WordDocument.cs:line 692

Any idea?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
J

Jialiang Ge [MSFT]

Hello Dave,

From your post, my understanding on this issue is: you want to know why
your application throws ErrorCode -2146823683 when it tries to add a field
at the end of a table row. If I'm off base, please feel free to let me know.

I reproduce the issue in my side and find that the table in Word actually
does not allow any text or field appended at the end of its rows. If you do
this directly in Word VBA, it might give you a more meaningful exception:
"This is not a valid action for the end of a row".

My suggestion is to detect whether the current caret is at the end of a row
mark:
If (Application.Selection.Range.IsEndOfRowMark)
If the above statement returns true, we may tell the users that the
operation is not allowed.

Please let me know if you have any other concerns, or need anything else.

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top