Missing reference vs unchecked reference runtime

Kyle123

Well-known Member
Joined
Jan 24, 2012
Messages
2,771
I am in the unenviable position of coming up with a workbook that does a load of VBA for people with computers that I do not know the spec of. I know the below works when I remove the reference to MSXML, however am I likely to run into any issues should the relevant MSXML library be missing rather than me unselecting whilst testing? I don't know whether missing behaves differently to an unchecked reference.

Rich (BB code):
    Dim request As IWebRequest
    Dim parser As IDataParser

    Set request = New DataRequest

    request.Url = CONSTANTS.Url
    request.Authenticator = CONSTANTS.AUTH_STRING
    request.Timeout = 12
    request.CallType = Legacy
    
    If LateBind Then
        Set parser = New LegacyDataParser
    Else
        Set parser = New DataParser
    End If
    
    Set parser.WebRequest = request


IDataParser
Rich (BB code):
Public Property Set WebRequest(ByVal RHS As IWebRequest): End Property
Public Property Get WebRequest() As IWebRequest: End Property

Public Function GetData() As Variant: End Function

DataParser
Rich (BB code):
Option Explicit
Implements IDataParser

Private m_IWebRequest As IWebRequest

Private Function IDataParser_GetData() As Variant

    Dim doc As Object
    Set doc = New MSXML2.DOMDocument60

    doc.LoadXML m_IWebRequest.GetData
    IDataParser_GetData = ParseData(doc)
    
End Function
'...

LegacyDataParser
Rich (BB code):
Option Explicit
Implements IDataParser

Private m_IWebRequest As IWebRequest

Private Function IDataParser_GetData() As Variant

    Dim doc As Object
    Set doc = CreateObject("MSXML2.DOMDocument")

    doc.LoadXML m_IWebRequest.GetData
    IDataParser_GetData = ParseData(doc)
    
End Function

I've previously posted this at EF here, but had no response: https://www.excelforum.com/excel-pr...reference-vs-unchecked-reference-runtime.html
 
Have you considered using CallByName on an object of the library and wrap it in a Boolean function? If the lib us not available (missing or unselected) it should raise a runtime error which can be handled and thus allowing code to decide between early and latebind.
 
Last edited:
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
No... I take back what I said.

The CallbyName Method would only be useful for determining the version of the library not if it is misiing.

Sorry.
 
Upvote 0
Thanks Jaafar, in this case I reckon checking for the presence of msxml6.dll should be enough to check whether the reference would be missing. I hadn’t thought of automating it, much appreciated!
 
Upvote 0

Forum statistics

Threads
1,214,981
Messages
6,122,565
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top