2

I would like to Run/execute a model within ArcMap 9.3.1 vba. I can run it in vba by exporting out the VBS script and importing it into vba, however I'm wondering if there is an easier way to just call the model by where it is located instead of using the VBS script (e.g. see below).

Run "C:\Data\New File Geodatabase.gdb\Toolbox\Model"

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 7, 2011 at 17:43

1 Answer 1

4

This code will run existing tools or models that your create:

Private Sub opentool_Click()
'Ensure that there are references set to the
'ESRI GeoprocessingUI Object Library and the
'ESRI Geoprocessing Object Library.
'Go to Tools > References to do this
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
'* Use this line for custom tools or models
'* ========================================
Set pTool = pAtb.GetToolbyNameString("Model8")
'* Use this line for existing tools
'* ================================
'Set pTool = pAtb.GetToolbyNameString("buffer_analysis")
Dim pCommand As IGPToolCommandHelper
Set pCommand = New GPToolCommandHelper
pCommand.SetTool pTool
pCommand.Invoke Nothing
End Sub

Right click on your tool in ArcToolox and go to properties to find the model name. alt text

answered Jan 7, 2011 at 20:30
5
  • Thanks for your reply. So the model dialog opens, I click OK to run and I get this error. Commented Jan 10, 2011 at 12:51
  • WARNING 000728: Field GeoPhyLogs does not exist within table Commented Jan 10, 2011 at 12:52
  • ERROR 000735: Input Table: Value is required, ERROR 0007: Input Dataset: Value is required, ERROR 000735: Join Table: Value is required, ERROR 000735 Input Table is required, WARNING 000728: Field BUFF_DIST does not exist within table, The value does not exist. Commented Jan 10, 2011 at 12:55
  • However, the model does run fine when I open the model via edit and run it. Commented Jan 10, 2011 at 12:56
  • I forgot to add some references to my project, your code works fine. Is there a way to automate a "Enter" keystroke or to click the "Ok" button when the model dialog opens? Commented Jun 24, 2011 at 19:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.