Page number in header (Page currentPage of TotalPages ), where TotalPages as Hyperlink to last page of the document RRS feed

  • Question

  • I want the header of the page in the format " Page currentPageNumber of totalPagesInDocument"

    I could achieve this, but I need a hyperlink for the "totalPagesInDocument" such that when clicked it navigates to the last page of the document.

    I tried with bookmarks, but I do not know how to make the totalPagesInDocument behave like hyperlink.

    Can this be achieved.

    Friday, January 4, 2019 12:05 PM

All replies

  • You need to understand that header content is essentially independent of the page content. So, if you bookmark the NUMPAGES field (which is what Word uses in this case), any hyperlink to that bookmark won't take you to the last page but to that field on the current page. In any event, you don't need a hyperlink for fast access to the last page - Ctrl-End will do that.

    Paul Edstein
    [MS MVP - Word]

    Friday, January 4, 2019 9:58 PM
  • Thanks for the clarification. I will explain in detail the requirement I have.

    I have different modules in a word document.

    For ex :

    Module1 ranges from 1 to 10

    Module2 ranges from 11 to 20 and so on...

    In the headers of page numbers where Page 1 of 10 is mentioned, 10 would be a hyperlink. When clicked on 10, it should navigate to page number 10 which is the last page of that module.

    For simplicity I had mentioned that the hyperlink in header should navigate to last page of the document

    Can my requirement be achieved ?

    Saturday, January 5, 2019 4:17 PM
  • You do realise, don't you, that to click on the 10 or 20, you'd have to open the header/footer for editing? Otherwise, you can't click on the number there. Moreover, if you turn the 10 or 20 into a hyperlink, it will no longer update if you edit the document so that the page count changes. And, finally, to be able to hyperlink to whatever page 10 or 20 might be, you'd need to put a bookmark on that page so you can hyperlink to it; any subsequent edits on that page might result in the bookmark being deleted and subsequent edits on any page might result in the bookmark being on the wrong page.

    So, possible? Yes. Practical? No.

    Paul Edstein
    [MS MVP - Word]

    Saturday, January 5, 2019 8:08 PM
  • I am converting the word document into PDF. So, when I click on the page number 10, it wont go into edit mode(as it is PDF). I created a word document and in the header section created a hyperlink to a bookmark which is on next page, next I converted that word doc in pdf. When I open PDF and click on the hyperlink which is present in the header, it does navigate to the bookmark on next page. The only issue I am facing is, I am not able to assign a bookmark to the hyperlink I created. I gives me exception of 'bad parameter' when I do not provide the web address while creating the hyperlink. Error comes at line - 'bookmark1.Range.Hyperlinks.Add'

    Code :

    myDoc.Paragraphs[1].Range.Text =



    Bookmarkbookmark1 =myDoc.Bookmarks.Add(


    objectposition = bookmark1.Range.End + 1;

    objecttextToDisplay = "Hi";

    //object Address = "";

    bookmark1.Range.Hyperlinks.Add(position ,

    refoMissing, refoMissing, refoMissing, reftextToDisplay);


    Basic requirement :

    We can insert a hyperlink anywhere within that document by choosing Place in this document option that is available when you click on "Insert-Hyperlink-Place in this document-Bookmarks-Bookmark1"

    Can you provide a way to achieve above line using c# code ?

    I tried with the above code but getting excpetions of type - bad parameter, command failed.

    If "Basic requirement " is achieved using C#, I can achieve my requirement of hyperlink in page header.

    • Edited by PS20 Monday, January 7, 2019 5:44 AM
    Monday, January 7, 2019 5:05 AM
  • Ordinarily, you don't hyperlink a bookmark - you hyperlink to one. That said, using VBA you could bookmark a hyperlink with code like:

    ActiveDocument.Bookmarks.Add Name:="BkMkNm", Range:=ActiveDocument.Hyperlinks(1).Range

    I'll leave it to you to do the C# conversion.

    Paul Edstein
    [MS MVP - Word]

    Monday, January 7, 2019 6:40 AM