locked
Inserting hyperlink programmatically into Word document using C#.NET RRS feed

  • السؤال

  • Hello,

    I have problems inserting hyperlinks using c# and the word/office API into a document.

    I have a list of bookmarks in a document and I want to create an appendix table with the names of the bookmarks being hyperlinks to the bookmark range in the document.
    I also have problems just creating hyperlinks in normal text.

    I'm doing this:
    doc.Hyperlinks.Add(anchor, ref missing,
                                ref subaddress, ref missing, ref missing, ref missing);

    I get the error: System.Runtime.InteropServices.COMException: Command failed at Microsoft.Office.Interop.Word.Hyperlinks.Add(Object Anchor, Object& Address, Object& SubAddress, Object& ScreenTip, Object& TextToDisplay, Object& Target)
    doc.Hyperlinks.Add(anchor, ref missing, ref subaddress, ref missing, ref missing, ref missing);

    All parameters except anchor are optional.
    The subaddress is a bookmark:
    object subaddress = FindBookmark(doc.Bookmarks, com);
    I've have also tried with the name of the bookmark, Bookmark.Name property, and using missing instead of subaddress; same error.

    Does anyone have examples of creating hyperlinks?  Either into text or tables.


    I'm using C# in Visual Studio 2005 and Word 2003.

    Thanks,

    Jens
    29/محرم/1427 12:31 م

الإجابات

جميع الردود