2

I am now looking for a code in VBA that can call Tools from ArcToolBox(The little red box)

I have find a Arcobject code(I thought it's can run under VBA) but it's don't work!

I have to delete the URL here....

in the end of the page it's have Arcobject code

But it's don't work!

can anyone tells me how to use it?

thanks for the help!!

@ Mike Toews

Compile error:

Sub or Function not defined

at OpenPointDataset

@artwork21 I call it from Tools>marcos>visual basic editor It's a simple compiler in GIS not a ui control

I have tried the method with the page:

Running a geoprocessing tool using the GPDispatch Object | ESRI Developer Network (Wayback Machine link)

and I try my Kriging Tool

Sub RunGPTool()
 'Create the Geoprocessor object
 Dim GP As Object
 Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")
 'Set the toolbox
 GP.Toolbox = "C:\Program Files\ArcGIS\ArcToolBox\Toolboxes\Spatial Analyst Tools.tbx"
 'Execute tools
 GP.Kriging "C:\sample.shp", _
 "F30", "C:\AA456円.shp", "250", "12"
 End Sub

but it's highlight error at GP.Kriging "C:\sample.shp", _ "F30", "C:\AA456円.shp", "250", "12"

and says
automation error
unspecified error

how to fix it??

update 2011年06月11日 10:00PM(+8)

@Casey

Running a geoprocessing tool using the GPDispatch Object | ESRI Developer Network (Wayback Machine link)

in this page

there is no "_analysis"in the sample code...

and I tried GP.Kriging_sa

but it's still don't work....

thanks for you support!

by the way I have tried buffer it's works!!

bixb0012
2,8681 gold badge7 silver badges19 bronze badges
asked Jun 9, 2011 at 7:46
2
  • Elaborate on how it does not work, e.g. error messages, etc. Commented Jun 9, 2011 at 9:56
  • how are you calling the code, from a UI Control or macro? Commented Jun 9, 2011 at 11:20

1 Answer 1

3

Here is sample code from ESRI on one method to run a Toolbox tool from VBA: Running a geoprocessing tool using the GPDispatch Object | ESRI Developer Network (Wayback Machine link)

In my experience it's a lot easier to call the Toolbox Tools from the command line or python (scripting). The help page for each tool contains code samples for both of these methods, for example: https://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=intersect_%28analysis%29

UPDATE 6/10/11

It looks like the ESRI code sample doesn't work as is (go figure). You need to comment out the gp.Toolbox line and add the name of the toolbox to the references of the tools. For example, to fix the sample code:

 Sub RunGPTool()
 'Create the Geoprocessor object
 Dim GP As Object
 
 Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")
 
 'Set the toolbox --COMMENT OUT THE GP.Toolbox LINE
 'GP.Toolbox = "D:\ArcGIS\ArcToolbox\Toolboxes\Analysis Tools.tbx"
 
 'Execute tools --APPEND THE NAME OF THE TOOLBOX TO THE TOOL
 GP.Clip_analysis "D:\Workspace\Portland.mdb\Region\streets", _
 "D:\Workspace\Portland.mdb\Region\downtown", "D:\Workspace\Portland.mdb\Region\dt_streets"
 
 GP.Buffer_analysis "D:\Workspace\Portland.mdb\Region\dt_streets", _
 "D:\Workspace\Portland.mdb\Region\dt_streetsbuf", "500"
 End Sub

Here is what I tested on my machine (I don't have Spatial Analysis to test your code):

 Sub RunGPTool()
 'Create the Geoprocessor object
 Dim GP As Object
 Set GP = CreateObject("esriGeoprocessing.GpDispatch.1")
 
 'Set the toolbox
 'GP.Toolbox = "D:\ArcGIS\ArcToolbox\Toolboxes\Analysis Tools.tbx"
 
 'Execute tools
 GP.MakeFeatureLayer_management "C:\Temp\NKCDC.shp", "temp_NKCDC"
 
 End Sub

You would change

 `GP.Kriging`

to

 `GP.Kriging_sa`
bixb0012
2,8681 gold badge7 silver badges19 bronze badges
answered Jun 9, 2011 at 13:18

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.