Convert early-binding code to late-binding

限于喜欢 提交于 2019-12-12 18:15:13

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5341544/convert-early-binding-code-to-late-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!