Here is sample code from ESRI on one method to run a Toolbox tool from VBA: http://edndoc.esri.com/arcobjects/9.0/Samples/Geoprocessing/RunToolWithGPDispatch.htm.
There has been some user discussion regarding this that may help:
http://forums.esri.com/Thread.asp?c=93&f=992&t=132081
http://forums.arcgis.com/threads/6117-Strange-problem-running-GP-tools-from-VBA
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: http://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
Best Answer
It really depends on how much code you are talking about. Most people try to go the other way, that is VB6\VBA to c# or vb.net.
But for your case a start might be to convert the methods to VB.net and then clean up the code to VBA.
C# <-> VB.net translator