1
votes

While trying to create a ms word document programmaticly, i came across a problem:

I am trying to find (without success) a way to create a HyperLink or something else that will do the work, that will navigate the user to another place in the document

A place can be a bookmark or some other paragraph object i inserted before

In the word application, i select a text, right click, press hyperlink and point the link to a "place in the document"

I cant find a way to it in C#

help?

2
Cross reference is the term you're looking for, which might make googling easier. I think you'll need Range.InsertCrossReference.Stefan

2 Answers

2
votes

Beside adding a CrossReference, there is also the possibility to use hyperlink

although the hyperlink is said to link to web url's, it can also direct to you to in-document text by using it like this:

        Microsoft.Office.Interop.Word.Paragraph oPara2;
        object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
        oPara2 = oDoc.Content.Paragraphs.Add(ref oRng);
        oPara2.Range.Text = "Heading 2";
        oPara2.Format.SpaceAfter = 6;
        oPara2.Range.InsertParagraphAfter();
        oDoc.Bookmarks.Add("BookmakrName3", oRng);


        object oAddress = "#BookmakrName3";

        //Add text after the chart.
        wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
        wrdRng.InsertParagraphAfter();
        wrdRng.InsertAfter("Click here to jump");
        wrdRng.Hyperlinks.Add(wrdRng, ref oAddress);

Note that there is a '#' before the bookmark name in the address given.. this is the trick

1
votes

If you want to do that more often with other Word documents, you might take a look at Latex, which can create very fast references inside your document, but generates a PDF instead. Now the question is, does your Word should still be editable later, if yes, then I would go for Ranger.InsertCrossReference.

Example about InsertCrossReference:

http://msdn.microsoft.com/fr-fr/library/microsoft.office.tools.word.bookmark.insertcrossreference.aspx

About what is latex.

http://fr.wikipedia.org/wiki/LaTeX

Here you can write online your latex document.

https://www.sharelatex.com/