Removes unused hyperlinks from the hyperlink collection of the document. Returns the number of remaining hyperlinks in the hyperlink collection of the document.
Applies to: Document object
[[Let] countRet =] object.RemoveUnusedHyperlinks () |
The RemoveUnusedHyperlinks method syntax has these parts:
Part | Description |
object | Required. An expression, that returns an instance of the Document object. |
countRet | Optional. A Long type variable. |
A hyperlink is considered unused if from all shapes and characters in the document there is no one, which Hyperlink property would match the ID (the ID property) of the hyperlink. After you use this method, be careful when working with references to instances of the Hyperlink object, because the instances of the objects to which they referenced may no longer exist (be removed).
This example contains a document-level script. It demonstrates how the RemoveUnusedHyperlinks is used for two hyperlinks, added by using the AddHyperlinkToFile method. Also it shows how an error may occur when an instance of the Hyperlink object, pointing to a non-existing hyperlink, is used.
' Declare variables Dim hlinkID1 As Long Dim hlinkID2 As Long Dim shp As Shape Dim hlink1 As Hyperlink Dim hlink2 As Hyperlink ' Add to the hyperlink collection of the document ' two new hyperlinks to files hlinkID1 = thisDoc.AddHyperlinkToFile( "1.cdd" ) hlinkID2 = thisDoc.AddHyperlinkToFile( "2.cdd" ) ' Get the hyperlinks by their IDs Set hlink1 = thisDoc.HyperlinkByID( hlinkID1 ) Set hlink2 = thisDoc.HyperlinkByID( hlinkID2 ) ' Draw a shape and assign the first hyperlink to it Set shp = thisDoc.ActivePage.DrawRect( 100,100,700,300 ) shp.Text = "1.cdd" shp.Hyperlink = hlinkID1 ' Remove unused hyperlinks from the hyperlink collection of the document; ' the hyperlink with ID 2 will be removed because it's not assigned to ' any object. thisDoc.RemoveUnusedHyperlinks() ' Display the Address property ' of any of the two added hyperlinks TRACE "Hyperlink_1 = " & hlink1.Address ' The same for the second hyperlink! ' This code can cause a run-time error, because the ' hyperlink, referenced to by the hlink2 variable, |