Sunday, 7 January 2018

VBA Using GetObject with a CLSID to create a COM object

I've just seen a nice syntax for how to create a COM object using GetObject but without supplying a ProgID and instead supplying a CLSID. The following code creates an instance of Internet Explorer without mentioning its name. I love GetObject, its like a little door into a secret garden.


Sub NoProgId()

    Dim objIE As Object
    Set objIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")

    Debug.Assert TypeName(objIE) = "IWebBrowser2"

End Sub


No comments:

Post a Comment