vba14-2.txt
来自「本书给出了AO的常用的VAB代码 可能是初学者很好的一本参考书」· 文本 代码 · 共 28 行
TXT
28 行
Private Function LoadShapefile(strPath As String, _
strFile As String, strName As String) As ILayer
' Load the shapefile based on the given path and name.
' Shapefile is added to the focus map as a layer.
' Layer is returned when successful.
Dim pWorkspaceFactory As IWorkspaceFactory
Dim pFeatureWorkspace As IFeatureWorkspace
Dim pFeatureClass As IFeatureClass
Dim pFeatureLayer As IFeatureLayer
Dim pMxDocument As IMxDocument
Dim pMap As IMap
Set pWorkspaceFactory = New ShapefileWorkspaceFactory
Set pFeatureWorkspace = pWorkspaceFactory. _
OpenFromFile(strPath, 0)
Set pFeatureClass = pFeatureWorkspace. _
OpenFeatureClass(strFile)
Set pFeatureLayer = New FeatureLayer
Set pFeatureLayer.FeatureClass = pFeatureClass
' Set the name and visibility of the layer.
pFeatureLayer.Name = strName
pFeatureLayer.Visible = True
' Add the shapefile to the focus map.
Set pMxDocument = Application.Document
Set pMap = pMxDocument.FocusMap
pMap.AddLayer pFeatureLayer
Set LoadShapefile = pFeatureLayer
End Function
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?