Note: This article pertains to ArcGIS versions 8.x. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.
This article provides an example of programmatically creating hyperlinks for selected features using ArcObjects.
Note: Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward
Note: For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
Dim pMxDoc As IMxDocument Dim pMap As IMap Dim pLayer As IFeatureLayer Dim pHyperlink As IHyperlink Dim pHyperlinkContainer As IHyperlinkContainer Set pMxDoc = ThisDocument Set pMap = pMxDoc.FocusMap 'Get the selected features from the layer Set pLayer = pMxDoc.SelectedLayer If pLayer Is Nothing Then MsgBox "Please select a layer" Exit Sub End If Dim pFSel As IFeatureSelection Set pFSel = pLayer Dim pSelSet As ISelectionSet Set pSelSet = pFSel.SelectionSet 'Make sure features are selected If pSelSet.Count < 1 Then MsgBox "Please select some features" Exit Sub End If 'Get the hyperlink from the user Dim strLink As String strLink = InputBox("Enter the Hyperlink", "Get Hyperlink") 'Loop through the selected features and add the hyperlink Dim pFeature As IFeature Dim pCur As IFeatureCursor pSelSet.Search Nothing, False, pCur Set pFeature = pCur.NextFeature 'The layer to add hyperlinks Set pHyperlinkContainer = pLayer Do Until pFeature Is Nothing Set pHyperlink = New Hyperlink pHyperlink.LinkType = esriHyperlinkTypeURL pHyperlink.Link = strLink pHyperlink.FeatureId = pFeature.OID pHyperlinkContainer.AddHyperlink pHyperlink Set pFeature = pCur.NextFeature Loop