How to invoke a geoprocessing tool from a button on a toolbar


This sample shows how to invoke a geoprocessing tool from a button on a toolbar without parameters.

How to use

  1. Copy the function into VBA. You will need to have a UI Button set up. This code will go in the Click method for that button.
  2. You will need to have ESRI Geoprocessing and ESRI GeoprocessingUI Libraries referenced.
[VBA]
Private Sub UIButtonControl1_Click()
    Dim pApp As IApplication
    Set pApp = Application
    
    Dim pUID As New UID
    pUID = "esriGeoprocessingUI.ArcToolboxExtension"
    
    Dim pATBExt As IArcToolboxExtension
    Set pATBExt = Application.FindExtensionByCLSID(pUID)
    
    Dim pAtb As IArcToolbox
    Set pAtb = pATBExt.ArcToolbox
    
    Dim pTool As IGPTool
    Set pTool = pAtb.GetToolbyNameString("buffer_analysis")
    Dim pCommand As IGPToolCommandHelper
    Set pCommand = New GPToolCommandHelper
    pCommand.SetTool pTool
    pCommand.Invoke Nothing
End Sub