VBA: Export All Metadata in a Geodatabase

Written by Bert Granberg,

Updated 7/7/09

This an old script that AGRC uses to export all the metadata from a geodatabase (ArcSDE database, file-based GDB, etc) into .html files.

The script runs in ArcMap and requires one layer be added to the project from the geodatabase.

You can specify different style sheets from the arcgis metadata stylesheets directory.

Public Sub getSGIDWorkspace()
  'get variables for accessing current map document
  Dim pMxDoc As IMxDocument
  Dim pMap As IMap
  Set pMxDoc = ThisDocument
  Set pMap = pMxDoc.FocusMap
 
  'get the vector feature layer in the map that has the same source workspace (gdb92.agrc.utah.gov)
  'as all the feature datasets that we wish to create metadata for
  Dim pFLayer As IFeatureLayer
  Set pFLayer = pMap.Layer(0)
  Dim pFClass As IFeatureClass
  Set pFClass = pFLayer.FeatureClass
  Dim pDataset As IDataset
  Set pDataset = pFClass
  Dim pWorkspace As IWorkspace
  Set pWorkspace = pDataset.Workspace
 
  'make a collection of featuredatasets in the source workspace
  Dim pDSNames As IEnumDatasetName
  Set pDSNames = pWorkspace.DatasetNames(esriDTFeatureClass)
 
  Dim pFCNames As IEnumDatasetName
  Dim pDSName As IFeatureDatasetName
  Dim pFCName As IFeatureClassName
  Dim pFCDSName As IDatasetName
  Dim pMetadata As IMetadata
  Dim pMetadataPropertySet As IXmlPropertySet2
 
  'Iterate through all featureclasse in source workspace (of layer 0)

  Set pFCName = pDSNames.Next

  Do While Not pFCName Is Nothing

        'Query Interface so we can get the name property of the featureclassname object

        Set pFCDSName = pFCName
        Set pMetadata = pFCName 'Query Interface so we can get the metadata property set

        'get metadata property set
        Set pMetadataPropertySet = pMetadata.Metadata

        'export metadata using xsl style sheet
        pMetadataPropertySet.SaveAsFile _
            "C:\Program Files\ArcGIS\Metadata\Stylesheets\fgdc.xsl", _
            "<!-- AGRC " & Now & " -->", True, _
            "J:\ftp\pub\SGID93_Vector\NAD83\MetadataHTML\" & _
            Replace(pFCDSName.Name, ".", "_") & ".html"

        'prepare for next featureclass iteration
        Set pFCName = pDSNames.Next
  Loop

End Sub

 


Users' Comments  
 

No comment posted

Add your comment

16, Dec. 2008
Last Updated ( 07, Jul. 2009 )