• Identifying failed hyperlinks in Word document (Any)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Identifying failed hyperlinks in Word document (Any)

    Author
    Topic
    #429457

    Hi

    I want a macro that checks that all hyperlinks in a Word document will work? I envisage it would work like this:

    1. Troll through all the fields
    2. Identify those that are hyperlinks
    3. Check whether the hyperlink’s target exists

    I was going to have a go at it myself, but then thought that someone’s sure to have done the work before. Is anyone aware of such a macro?

    PS: I searched WOPR for “failed AND hyperlink” before making this post, and was astonished to get only one hit. What’s wrong with you people, don’t you ever make any mistakes? grin

    Thanks
    Dale

    Viewing 3 reply threads
    Author
    Replies
    • #1000214

      What is the target of the hyperlinks? Files, URLs, e-mail addresses, a mixture?

      • #1000216

        Hi Hans

        I was thinking of using it for Word documents that are going to be subjected to a process that creates an HTML version. I guess all the targets will be in one of the the following formats:

        • http address (eg, http://support.microsoft.com)
        • www address (eg, http://www.microsoft.com) (but I think Word might convert that to an http anyway)
        • filename (eg, abc.htm or abc.doc or abc.pdf or …)
        • filename at relative address (eg xyzabc.htm or ….downloadsabc.doc)[/list]In fact, it’s more than just hyperlinks, isn’t it. For example, images should be included (field type of INCLUDEPICTURE), and no doubt there are others.

          And I guess a full blown solution would also handle formats such as file://. And I suppose it sould also create a report containing warnings (eg, any “file://” address is suspect since it will fail when published on the net).

          However, if anything’s out there, I’d be very interested. And if there isn’t anything available, I’ll have a go myself, but starting small.

          Thanks
          Dale

        • #1000218

          I, for one, don’t have anything ready. If you create something yourself, please share it here. Thanks in advance.

    • #1000443

      Dale, this is the mess of potage I came up with. It represents several chunks of code from my WbWrd and my utility library. It is not a final solution for you, but it shows you some of the contortions my mind went through about seven years ago. I know I test for different field types, and then performs actions depending on.

      1) If it is a hyperlink to a supposedly existing web page, I just leave it as is.
      2) A hyperlink to a Word doc is resolved to that doc, I open the doc and recurse.
      3) A hyperlink to a file is resolved to that file; I’m supposed to copy that file on my hard drive to an upload flder.
      4) Not sure what i do with mailto’s
      5) I used to examine IncludeText fields, but they turned out to be a red herring.

      • #1000446

        Hi Chris

        That’s really kind and will get me off to a flying start. I’ll post something back here when I (eventually) get somewhere with it.

        Thanks
        Dale

    • #1000456

      Dale

      I asked a similar question a while back, but didn’t find anything out there (post 66,767). I then spent weeks trying to create something with VBA, but gave up thinking that I just couldn’t do it.

      What I did instead was start using a programme that checks the links in the HTML files once they’ve been created, and then fix any broken links in the Word documents before creating them again. The programme is HTML Link Validator, and it works well (though it can be tricky checking links that are activated via JavaScript).

      Good luck.

    • #1005142

      Hi

      As promised, attached is an attempt at checking for failed hyperlinks (and INCLUDEPICTURE targets) in Word documents.

      • #1168147

        Hi

        As promised, attached is an attempt at checking for failed hyperlinks (and INCLUDEPICTURE targets) in Word documents.

        I came here hoping to find VBA code that lets me verify the hyperlinks in a Word 2007 document. It sounds like the attachment that used to be here would get me going in the right direction, but the attachment appears to be missing. I guess it was dropped when Woody’s Lounge got rejiggered and upgraded. Any of you administrative types know if and where I could find this code?

        Thanks

        • #1168162

          if and where I could find this code? Thanks

          I think this is the code I was referring to; I think Dale took it and developed something based on my ideas.
          This code comes from my “web word” compiler; It looks at each hyperlink in a document, and if the hyperlink points to an existing document, it processes THAT document.
          It is a document crawler, same idea as a web crawler.
          It processes each document only once, since the hyperlink structure may not be a true tree, that is, it may contain circular links.

          Code:
          Function ProcessHyperlinkTreeOfDocument(doc As Document)
          	Dim hlink As Hyperlink
          	For Each hlink In doc.Hyperlinks
          		Dim strHlinkName As String
          		strHlinkName = (hlink.Name)
          		Call AMLog(ThisDocument, "ProcessDocument with " & strHlinkName, os.blnMsgBox, True)
          		If blnDocumentLink(strHlinkName) Then
          			' Process this linked document
          			Dim strDocumentFullName As String
          			strDocumentFullName = strMakeFullName(doc, strHlinkName)
          			If UW.blnFileExists(strDocumentFullName) Then
          				If InStr(1, strOpened, strDocumentFullName) > 0 Then ' already processed
          					Call AMLog(ThisDocument, "ProcessDocument already processed " & strDocumentFullName, os.blnMsgBox, True)
          				Else
          					strOpened = strOpened & strDocumentFullName
          					Dim docLink As Document
          					Call AMLog(ThisDocument, "ProcessDocument opening " & strDocumentFullName, os.blnMsgBox, True)
          					Set docLink = Documents.Open(strDocumentFullName)
          					Call ProcessADocumentTree(docLink)
          					Call AMLog(ThisDocument, "ProcessDocument closing " & docLink.FullName, os.blnMsgBox, True)
          					docLink.Close (wdDoNotSaveChanges)
          					DoEvents ' required to avoid "losing" a hyperlink, believe it or not.
          				End If
          			Else
          				Call AMLog(ThisDocument, "ProcessDocument could not find" & strDocumentFullName, os.blnMsgBox, True)
          			End If
          		Else
          		End If
          	Next hlink
          End Function
          • #1168604

            It looks the the ProcessADocumentTree code is code that actually manipulates the hyperlinks. Is this code built in VB, outside VBA and Word? I’m trying to verify hyperlinks (Web only) in Word 2007 while the document is open. It meatspace, this sounds like a much simpler process than what you’ve done. In cyberspace, though, it might be just as complicated.

    Viewing 3 reply threads
    Reply To: Identifying failed hyperlinks in Word document (Any)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: