I've often written early-binding code in VBA and VB6 to automate office applications (Word, Excel, etc) then switched it to late-binding to handle multiple versions of those applications. I'm trying to do the same thing but I am automating an ESRI ArcMap GIS application and the concepts I've used in the past do not seem to be translating.
The following code runs correctly:
Sub EarlyBinding()
Dim ArcMap As esriArcMapUI.MxDocument
Set ArcMap = GetObject("C:\Users\Mike\Downloads\Assessment Mapping.mxd", _
"esriArcMapUI.MxDocument")
Debug.Print ArcMap.Title
开发者_开发问答End Sub
But this code fails with Object doesn't support this property or method on the Debug.Print
line:
Sub LateBinding()
Dim ArcMap As Object
Set ArcMap = GetObject("C:\Users\Mike\Downloads\Assessment Mapping.mxd", _
"esriArcMapUI.MxDocument")
Debug.Print ArcMap.Title
End Sub
Is there something special about MS Office apps that they support this approach better than COM servers in general? Or something special about ESRI apps that they do not support this approach?
It's most likely that the Esri object isn't supporting IDISPATCH properly. You might try CALLBYNAME, but I'm guessing that won't work either because I believe it vectors through IDispatch as well.
精彩评论