This tip shows you how to add a .lyr file as a layer to your dataframe.
How to use
- Copy-paste this procedure into the VB Editor in ArcMap.
- Change the location of the .lyr file to correspond to your ArcGIS installation.
- Run the procedure.
Private Sub AddLayerFromFile()
Dim pApp As IApplication
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pGxLayer As IGxLayer
Dim pGxFile As IGxFile
Dim strLayerPath As String
Set pGxLayer = New GxLayer
Set pGxFile = pGxLayer
' Set this variable to the location of you layer file
strLayerPath = "D:\ArcGIS\SampleMaps\Data\JoshuaTreeNP\Dem.lyr"
pGxFile.Path = strLayerPath
If Not pGxLayer.Layer Is Nothing Then
Set pApp = Application
Set pMxDoc = pApp.Document
Set pMap = pMxDoc.FocusMap
pMap.AddLayer pGxLayer.Layer
End If
End Sub