Visual Studio Development Bookmark and Share   
 index > Visual Studio Tools for Office > Selection.InsertCrossReference
 

Selection.InsertCrossReference

i am trying to write a c# Word addin to insert cross references to figure captions within the document.

whenever i try to use the selection.intsertCrossReference command i get an error : System.Runtime.InteropServices.COMException (0x800A1066): Command Failed

the code:

Document doc = WordApp.ActiveDocument;
oCRItems = doc.GetCrossReferenceItems(ref reftyp);
Array items = ((Array)(oCrossReferenceItems));

object
refitem = items.GetValue(1);
object oRefType = Word.WdCaptionLabelID.wdCaptionFigure;
object oRefKind = Word.WdReferenceKind.wdEntireCaption;

WordApp.Selection.InsertCrossReference(ref oRefType,Word.WdReferenceKind.wdEntireCaption,ref refitem,ref nullobj,ref nullobj,ref nullobj,ref nullobj);

any suggestions on what i am doing wrong?

thanks

MPJ_123  Wednesday, September 16, 2009 1:51 AM
Hi Bessie

thanks for the help. What I was doing wrong was trying to insert the wrong kind of reference for the reference type. I needed to match the the allowable kinds to the type, ie a figure type can have 'only labal and number' but not 'Content text'. when I was inserting the wrong kind i got the error reported above.

cheers
MPJ_123  Sunday, October 18, 2009 11:45 PM

Hi,

According tothe partialcode,I still cannot reproduce this issue. Showing more code here may be helpful.

Afterresearching a lot, here is a useful resource about Selection.InsertCrossReference: http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.bookmark.insertcrossreference(VS.80).aspx.

Hope this helps,
Bessie


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bessie Zhao  Tuesday, September 22, 2009 10:15 AM
We are changing the issue type to "General Discussion" because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to "Question" by opening the Options list at the top of the post window, and changing the type. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Bessie Zhao  Thursday, September 24, 2009 11:22 AM
Hi Bessie

thanks for the help. What I was doing wrong was trying to insert the wrong kind of reference for the reference type. I needed to match the the allowable kinds to the type, ie a figure type can have 'only labal and number' but not 'Content text'. when I was inserting the wrong kind i got the error reported above.

cheers
MPJ_123  Sunday, October 18, 2009 11:45 PM

You can use google to search for other answers

Custom Search

More Threads

• How to use DataConnections in Infopath 2007 OM
• How to embed PDF files in a Word 2007 document
• How to add Watermark?
• offline cache not working in excel document level customization
• Copy Paste problem with table
• how to make ms-word allow only one page
• Questons about the March 2007 article titled "Deploying Visual Studio 2005 Tools for Office Second Edition Solutions Using Wi...
• VSTO 2005 SE Outlook Add-in application does not load in Office 2003 Standard Edition
• Visual Studio Tools fo office
• Working with Microsoft Excel