none
Removing cross-references from word doc RRS feed

  • Question

  • Hi,

    I have a c# program that searches for specific strings in a word document and copies them to the UI. the problem is that when the string constitute a cross-reference, it is not found. I was trying to find how to remove all cross reference from the word doc, and leave only the text which they include. for example: "For more information see paragraph 3" (while 3 is cross reference). 

    This is the code I've tried to use in order delete the cross reference:

            public void Removehyperlink(Document oDoc)
            {
                Microsoft.Office.Interop.Word.Hyperlinks links = oDoc.Hyperlinks;
                for (int i = 0; i < links.Count; i++)
                {
                    object index = (object)i;
                    links[index].Delete(); //Here i am getting Com exception, see below
                }
                //Microsoft.Office.Interop.Word.


                Microsoft.Office.Interop.Word.InlineShapes inlineShapes = oDoc.InlineShapes;

                foreach (Microsoft.Office.Interop.Word.InlineShape iShape in inlineShapes)
                {

                    if (iShape.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapeEmbeddedOLEObject ||

                        iShape.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapeLinkedOLEObject)
                    {

                        iShape.Delete();

                    }

                }
            }



    this is where the search fails to find the number:

                    //Now Define & Search the rest of the document For the Number
                    DynamicContentRng = oDoc.Content;
                    DynamicContentRng.Start = Convert.ToInt32(startNumber);
                    DynamicContentRng.Find.Text = ".";
                    DynamicContentRng.Find.Forward = true;

    Tuesday, January 8, 2019 4:01 PM

All replies

  • Hi DorGoldi,

    This forum discusses and asks questions about the C# programming language, since your issue is more related to VSTO, I would suggest that you could post your issue on VSTO forum for suitable support.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vsto

    Thanks for your understanding.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 9, 2019 3:00 AM