How to hotlink a feature layer to a web site


The sample demonstrates one way to hotlink a feature layer to web pages.
Hotlinks use a field in the database to store the hyperlink address for a web page, document, or macro. When a hotlink is created for a feature layer, every feature in the layer is linked to the item listed in its hotlink field. If hotlink field is empty for a feature, that feature is simply not linked to anything.
Hyperlinks differ from hotlinks in that they are set up for an individual feature rather than an entire feature layer. In addition, hyperlinks do not use a field in the database to store the path to the link. See the Hyperlink Sample for an example of this.
Hyperlinks and hotlinks support three link types: documents, urls, and macros.

How to use

  1. Paste the code into VBA.
  2. Modify the code to reflect the correct hot link field. This sampleis hard-coded to use a field called WebLink.
  3. Select a feature layer in the table of contents.
  4. Make sure at least one feature from this layer has a web address in its hot link field.
  5. Run the AddHotlink Macro.
  6. Select the Hyperlink tool.
  7. All the features in this layer with a valid hot link field valueshould be outlined in blue.
  8. Using the Hyperlink tool, click on one of the features to launchthat features linked in web site.
[VBA]
Public Sub AddHotlink()
    Dim pMxDoc As IMxDocument
    Dim pContentsView As IContentsView
    Dim pHotlinkContainer As IHotlinkContainer
    
    Set pMxDoc = Application.Document
    Set pContentsView = pMxDoc.CurrentContentsView
    If TypeOf pContentsView.SelectedItem Is IFeatureLayer Then
        Set pHotlinkContainer = pContentsView.SelectedItem
        pHotlinkContainer.HotlinkField = "WebLink"
        pHotlinkContainer.HotlinkType = esriHyperlinkTypeURL
    End If
End Sub