This tip shows how to add a layer file to an open map document programmatically.
How to use
- Copy the subroutine to VBA Editor of an opened map document and change the filePath accordingly.
- Execute the subroutine.
Public Sub AddLayerFileToMap()
Dim filePath As String
filePath = "C:\Program Files\ArcGIS\DeveloperKit10.0\Samples\data\USA\states.lyr"
Dim pGxLayer As IGxLayer
Dim pGxFile As IGxFile
Set pGxLayer = New GxLayer
Set pGxFile = pGxLayer
pGxFile.Path = filePath
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
pMxDoc.FocusMap.AddLayer pGxLayer.Layer
End Sub