This sample demonstrates how to open a metadata editor from inside ArcMap using the IMetadataEditor interface. The sample opens a metadata editor for the selected item from the ArcMap Table of Contents. A check, to make sure the selected item is of type IDatalayer, is completed before the editor is opened. The sample was written in VBA and references the MetaEditor.dll.
How to use
- Paste this macro into VBA.
- Turn on the reference to the MetaEditor.dll: Within the VB Editor go to Tools > References and check the box for the MetaEditor reference.
- Select a Item in ArcMap.
- Run the macro.
Sub editMetadata()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pActiveView As IActiveView
Dim pLayer As ILayer
Set pMxDoc = esriArcMap.Application.Document
Set pMap = pMxDoc.FocusMap
Set pActiveView = pMap
'Get the selected Layer
If Not pMxDoc.SelectedItem Is Nothing Then
If TypeOf pMxDoc.SelectedItem Is ILayer Then
Set pLayer = pMxDoc.SelectedItem
Else
'handle other objects in ArcMap that are not layers
MsgBox "The selected item is not a Layer"
Exit Sub
End If
Else
MsgBox "Please select an Item"
Exit Sub
End If
If TypeOf pLayer Is IDataLayer Then
Dim pDLayer As IDataLayer
Dim pMD As IMetadata
Dim pPS As IPropertySet
Set pDLayer = pLayer
Set pMD = pDLayer.DataSourceName.Open
Set pPS = pMD.Metadata
'to show FGDC editor, need to reference ArcGIS\bin\MetaEditor.dll,
'This is found in the VBA editor through Tools > References > Metadata
Dim pMDEditor As IMetadataEditor
'Set the editor to the FGDC Editor.
'To use ISO use the following: Set pMDEditor = New ISOWizard.Editor
Set pMDEditor = New MetaEditor.MetaEdit
'Check to see if the metadata was edited
Dim bModified As Boolean
bModified = pMDEditor.Edit(pPS, 0)
'Save the metadata
If bModified Then pMD.Metadata = pPS
End If
End Sub