How do I check hyperlinks (many) in a Word 2002 document?

G

Guest

I've got a Word 2002 document containing ~120 hyperlinks. Both the document
and the linked-to documents reside on a shared network drive, and the linked
docs open a 3rd party viewer each time the link is invoked. I'd like a
built-in function, or a macro that will verify all the links in a doc whilst
I do something a bit more exciting. I'd rather the 3rd party viewer not run
- just have the macro check for the existance of the target file.
 
G

Guest

Dick:

This should get you started...

Sub x()
'
' x Macro
' Macro recorded 7/19/2007 by David Chinell
'
Dim objWorkRange As Range
Dim objField As Field
Dim aryCode() As String
Dim strFileName As String

' Set this to handle bad file formats

On Error Resume Next

' Work from the current insertion point down

Set objWorkRange = ActiveDocument.Range
objWorkRange.Start = Selection.Start

' Find all the hyperlinks

For Each objField In objWorkRange.Fields
' For each hyperlink, split out the filename
If objField.Type = wdFieldHyperlink Then
aryCode = Split(objField.Code, """")
strFileName = aryCode(1)
' Test whether the file exists
If Dir(strFileName) = "" Then
' The file is missing
objField.Select
MsgBox _
Prompt:="This link is invalid:" & vbNewLine _
& strFileName, _
Buttons:=vbInformation, _
Title:="LazyButt Tools"
Set objWorkRange = Nothing
Exit Sub
End If
End If
Next objField

Set objWorkRange = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top