I'm trying to devise some Word (2003 SP3) VBA code that will remove the file name (the hyperlink Address) from hyperlinks that're in the file in question. Attached is a document with such a link (don't ask how things like this come about - there are authors here who do weird things). I figured that the following code would work, but it just doesn't.
Code: Select all
Public Sub RemoveFileName()
Dim hypEachHyperlink As Hyperlink
With ActiveDocument
.Fields.Update
For Each hypEachHyperlink In .Hyperlinks
If hypEachHyperlink.Address = .Name Then
hypEachHyperlink.Address = vbNullString
End If
Next hypEachHyperlink
End With
End Sub
Using the attached document, it seems that the hyperlink Address ("tester.doc") and the file name ("tester.doc") are the same, and stepping through the code seems to activate the "hypEachHyperlink.Address = vbNullString" part, yet nothing happens. Replacing vbNullString with "" doesn't work either.
Can anyone suggest how I could make this work? I suppose I could remove the existing hyperlink and add a new one without an Address, but I was hoping to do something simpler.
You do not have the required permissions to view the files attached to this post.