locked
Hyperlinks not working correctly when converting word doc to Web Page, Filtered RRS feed

  • Question

  • I have created a word document (MS Word 2013) with Table of Contents and their links to particular sections and all the hyperlinks works fine in the word document. But when I convert this document into Web Page, Filtered then after a specific point the hyperlinks not pointing to their respective sections instead they are pointed to the end of the page.

    I have checked the page source of the HTML document and found that the table of contents have hyper links but the respective sections doesn't have the hyper link code and hence click on the a section didn't find the that section and go to the end of the document.

    I have tried to convert into PDF and hyperlinks worked fine.

    Please advise me how to resolve this issue.

    Thanks in advance

    Deepak

    Sunday, February 1, 2015 12:38 PM

Answers

  • Since the Table of Contents gets converted to a series of hyperlinks by the macro, I can't see how it would simply 'disappear'. Are you using a Table of Contents inserted via References|Table of Contents? If so, try deleting that and inserting one via Insert|Quick Parts|Field. The former embeds the Table of Contents in a content control, and that may be causing issues.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Steve Fan Monday, March 2, 2015 1:01 AM
    Tuesday, February 17, 2015 11:16 AM

All replies

  • Hi Deepak,

    I can reproduce this issue in my environment. This is the default behavior when we convert Word to Web Page. When we convert Word to web page, it doesn't separate content into pages like Word or PDF does. So, there is no much space if we scroll to the end of the web page. When we click a hyperlink to a section which is at the bottom of the web page, it will only go to the end of the document.

    To work around this issue, we need to add enough spaces (press Enter for several times until the mouse cursor is at the end of current page) at the end of the document and then convert it to Web Page.

    If you still have any question on this issue, please don't hesitate to post back.

    Regards,

    Steve Fan

    Forum Support


    Come back and mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback on our support, please click here

    Tuesday, February 3, 2015 3:28 PM
  • Hi Deepak,

    Just checking in to see if the information was helpful. Please let us know if you would like further assistance. 

    Best Regards,

    Steve Fan

    Forum Support


    Come back and mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback on our support, please click here

    Monday, February 9, 2015 1:26 AM
  • I tried to do the same but didn't get any success.

    Please see below the link of the word document, it might help to reproduce the issue on your end.

    http://1drv.ms/1zVE5Nz


    Please let me know if there is any other trick to fix this issue.

    Thanks,

    Deepak

    Tuesday, February 10, 2015 6:05 PM
  • The following macro converts a Table of Contents to Hyperlinks (without page #s). Since hyperlinks don't update the way TOC fields do, it's probably best to not do the conversion until the document is otherwise finalised. These hyperlinks may survive your HTML conversion better than the standard conversion.

    Sub ConvertTOC2Hyperlinks()
    Dim RngTOC As Range, RngItem As Range, StrBkMkList As String, StrTmp As String, i As Long
    With ActiveDocument
      With .TablesOfContents(1)
        .Update
        If InStr(.Range.Fields(1).Code.Text, "\n") = 0 Then
          For i = 3 To .Range.Fields.Count Step 2
            StrBkMkList = StrBkMkList & "|" & Split(Trim(.Range.Fields(i).Code.Text), " ")(1)
          Next
        Else
          For i = 2 To .Range.Fields.Count
            StrBkMkList = StrBkMkList & "|" & Replace(Split(Trim(.Range.Fields(i).Code.Text), " ")(2), """", "")
          Next
        End If
        Set RngTOC = .Range
      End With
      RngTOC.Fields.Unlink
      For i = 1 To UBound(Split(StrBkMkList, "|"))
        Set RngItem = RngTOC.Paragraphs(i).Range
        RngItem.End = RngItem.End - 1
        StrTmp = Replace(Split(StrBkMkList, "|")(i), "Toc", "HL")
        .Bookmarks.Add Name:=StrTmp, Range:=.Bookmarks(Split(StrBkMkList, "|")(i)).Range
        .Bookmarks(Split(StrBkMkList, "|")(i)).Delete
        .Hyperlinks.Add Anchor:=RngItem, SubAddress:=.Bookmarks(StrTmp).Range, _
          TextToDisplay:=.Bookmarks(StrTmp).Range.Text
      Next
    End With
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]




    • Edited by macropodMVP Thursday, February 12, 2015 8:26 AM Code revision
    • Proposed as answer by Stefan BlomMVP Monday, March 2, 2015 10:31 AM
    Wednesday, February 11, 2015 1:18 AM
  • Dear Paul,

    Thanks for your help but I tried to execute this macro and I got the error.

    "Run time error: 5941

    The requested member of the collection doesn't exist."

    I have tried to attache screen shot but site doesn't allow me to do that and I am getting message that my account is not verified yet so can't attach any email or link.

    Please check this issue and provide me the solution. 

    Thanks in advance.

    Deepak


    Wednesday, February 11, 2015 1:28 PM
  • I've revised the code. Try it now.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, February 11, 2015 7:44 PM
  • Hi,

    Just checking in to see if the information from Paul was helpful. Please let us know if you would like further assistance.

    Regards,

    Melon Chen

    Forum Support


    Come back and mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback on our support, please click here
    Monday, February 16, 2015 3:04 AM
  • Hi Paul,

    I couldn't find the revised code, could you please post it again.

    Thanks,

    Deepak

    Monday, February 16, 2015 7:31 AM
  • Paul edited his previous post; it should now include the updated code.


    Stefan Blom, Microsoft Word MVP

    Monday, February 16, 2015 1:46 PM
  • Hi Paul,

    I tried the revised code now it's working with any errors but once I run it on the word document and then covert to the Web page filtered then it removes Table of contents list completely.

    I also tried to run it on the webpage filtered file but then it shows error.

    Please advise.

    Thanks,

    Deepak

    Tuesday, February 17, 2015 10:06 AM
  • Since the Table of Contents gets converted to a series of hyperlinks by the macro, I can't see how it would simply 'disappear'. Are you using a Table of Contents inserted via References|Table of Contents? If so, try deleting that and inserting one via Insert|Quick Parts|Field. The former embeds the Table of Contents in a content control, and that may be causing issues.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    • Marked as answer by Steve Fan Monday, March 2, 2015 1:01 AM
    Tuesday, February 17, 2015 11:16 AM
  • Hi Deepak,

    Any update on this issue? Have you got any opportunity to try Paul's method?

    Regards,

    Steve Fan

    Forum Support


    Come back and mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback on our support, please click here

    Wednesday, February 25, 2015 1:29 AM
  • Hi Deepak,

    I'm marking the reply as answer as there has been no update for a couple of days.

    If you come back to find it doesn't work for you, please reply to us and unmark the answer.

    Best Regards,

    Steve Fan

    Forum Support


    Come back and mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback on our support, please click here

    Monday, March 2, 2015 1:00 AM
  • There is a bug with "Web Page, Filtered" that maybe the Word team are not aware of. I have confirmed this in both Word 2007 and 2010.

    To reproduce, I simply created a bookmark and a reference link to it, and then saved them in "Web Page" and "Web Page, Filtered" HTML formats.  The first works OK, although the HTML is verbose and not accepted by some other systems. The filtered format seems to be inconsistent. The displayed content (after the Save operation) looks OK, but the the *.html file has lost the reference link to the bookmark. If you copy-and-paste from the screen copy (immediately after the Save) to some HTML editor then the reference links are still lost but the HTML is significantly different to both the filtered copy in the *.html and to the full "Web Page" version.

    There are also problems with defining bookmarks that span other fields (e.g, "SEQ" for sequence-number generation), but that's probably a different issue.

    Let me know if you want any test samples.

    Thursday, December 1, 2016 3:50 PM
  • There is a bug with "Web Page, Filtered" that maybe the Word team are not aware of. I have confirmed this in both Word 2007 and 2010.

    To reproduce, I simply created a bookmark and a reference link to it, and then saved them in "Web Page" and "Web Page, Filtered" HTML formats.  The first works OK, although the HTML is verbose and not accepted by some other systems. The filtered format seems to be inconsistent. The displayed content (after the Save operation) looks OK, but the the *.html file has lost the reference link to the bookmark. If you copy-and-paste from the screen copy (immediately after the Save) to some HTML editor then the reference links are still lost but the HTML is significantly different to both the filtered copy in the *.html and to the full "Web Page" version.

      

    If you created a hyperlinked cross-reference in Word, it wouldn't be supported in the "Web Page, Filtered" format. However, a hyperlink (created via the Hyperlink dialog box) should be preserved.


    Stefan Blom, Microsoft Word MVP

    Thursday, December 1, 2016 8:11 PM
  • It creates the anchor point, but not the references to it. Also, the anchor-point stops after the first parenthesis, for some odd reason. For instance, when creating a bookmark called "L_1_2" over a piece of text that reads "L(1.2)", the full "Werb Page" HTML is correct but the filter one only marks the "L("

    As I said, too, copying HTML from the screen (after the Save-As) is quite different to copying it from the file, but I would have expected them both to be the same filtered version.

    Thursday, December 1, 2016 8:52 PM
  • Can I just add some useful clarification, and thoughts, before leaving this thread?

    1) I accept the difference between hyperlinked cross-references (to bookmarks), and [URL] hyperlinks to bookmarks, although the terminology is obviously confusing. The reason I wanted to use normal cross-references, rather than proper [URL] hyperlinks, is that you have the choice of displaying the bookmarked text. 99% of the time, you do not want the reader to see some raw symbolic connection in the text (i.e. the bookmark name); you want to show them a real title/phrase. The same obviously applies to raw URLs versus the title of the referenced item. With the [URL] hyperlinks to bookmarks, there's no option to display the bookmarked text. I don't see this being hard to provide, or upsetting anything else -- it may have even been an oversight -- and would like it to be considered.

    2) I discovered something while trying to make my bookmarks work: if I generate the link as hyperlinked cross-references then it looks good and will show the bookmarked text, as required. I then visited each of those links, selected the text, and inserted a [URL] hyperlink to the same bookmark. This changed the mechanism from the one that doesn't work in the filtered HTML to the one that does work, but it still looks like the former. This is an acceptable workaround for me but I would like to know if it was intentional.

    3) As I said earlier, when bookmarking a piece of text such as L(1.2.4) -- a custom labelling scheme that uses SEQ and STYLEREF field codes -- then all forms of the HTML, in both 2007 and 2010, only mark the "L(". This isn't a showstopper since at least the anchor is placed at the right location, but it certainly looks like a bug to me.  Bookmarking a simple bit of text with the same characters works OK, to it's obviously some sort of clash between bookmarks and field-codes in the "Web Page, Filtered" scenario.

    Many thanks for your help


    • Edited by ACProctor Saturday, December 3, 2016 4:14 PM Corrected description of 3rd issue
    Friday, December 2, 2016 11:25 AM
  • 1. Terminology is different between different programs and there is no doubt that this can be confusing. The conceptual difference between a cross-reference and a hyperlink is that the cross-reference displays information (content, page number, paragraph number, etc.) and can be updated when its target changes, while a hyperlink simply allows you to go to a different location (a location within the document or a location on the internet, for example).

    2–3. I believe the underlying problem here is that Word creates its own HTML coding to preserve its specific features, such as SEQ fields. Filtered HTML does not support that coding which is why you lose certain formatting/content.


    Stefan Blom, Microsoft Word MVP

    Sunday, December 4, 2016 3:30 PM
  • Thanks Stefan. I did some more investigation to see why my approach was working (i.e. creating a normal cross-reference hyperlink and then changing it to a URL hyperlink).

    As you say, the display text for the URL does not update. Also, the display text is not part of the HYPERLINK field code. However, by creating a normal cross-reference and then selecting it, I had established updateable display text which would automatically be used when converting to the URL hyperlink.

    That means I can use the cross-reference mechanism to nicely generate an updateable piece of bookmark text, convert it to a URL hyperlink (which works in the filtered HTML), avoid the clumsy-looking blue+underline used for normal hyperlinks, and the display text is *still* updateable.

    I just fear something might change in a later version to "fix" things.

    Sunday, December 4, 2016 5:17 PM