HOW TO

Save ArcMap VBA code to separate files on disk

Last Published: April 25, 2020

Summary

Note: 
Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward

This article shows how to save code in a VBA project to separate files.

Procedure

  1. Start ArcMap.
  2. Create a new UIButtonControl, See How To: Create a new UIButtonControl
Note: For more information on creating a UIControl, see the ArcGIS Desktop Help topic "Creating custom commands with VBA and UI Controls".
  1. Right-click the UIButtonControl and select View Source.
  2. Copy this code into the UIButtonControl's click event.
Dim myVBAProject As VBProject
Dim vbComp As VBComponent
Dim savePath As String

'Path to save exported files
savePath = "D:\MyVBAFiles\"
'Get the VBA project from the document and
'loop through all the components
'in the VBA project
Set myVBProject = Application.Document.VBProject
For Each vbComp In myVBAProject.VBComponents
    Select Case vbComp.Type
    Case vbext_ct_StdModule
        vbComp.Export savePath & vbComp.Name & ".bas"
    Case vbext_ct_Document, vbext_ct_ClassModule
        vbComp.Export savePath & vbComp.Name & ".cls"
    Case vbext_ct_MSForm
        vbComp.Export savePath & vbComp.Name & ".frm"
    Case Else
        vbComp.Export savePath & vbComp.Name
    End Select
Next

Article ID:000002001

Software:
  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic