References: CreateObject arguments for late binding

C

Cheer

This is really a two part question.

Part 1. Just for the sake of argument, suppose I, in developing an
Excel add-in, included a few extraneous References in the VBE - i.e.,
went to Tools/References and clicked on something I didn't really
need. For example, I see I have the "Microsoft Windows Installer
Object Library" checked, and I'm pretty sure I'm' not using anything
from that library. Will Excel uncheck an unused reference? If not, is
there an easy way to tell if that reference really needs to be
included?

Part 2. I would like to become a convert to late binding so I don't
have to add a lot of references programmatically. Is there a resource
somewhere that will tell me what to specify for the arguments for
"CreateObject" for things like "Microsoft HTML Object Library,"
"Microsoft XML, v3.0, " or "OLE Automation"? I''m most concerned with
how to do "Microsoft XML, v3.0" as I'm getting errors when I try to
install my add-in on machines other than my own. I understand I will
no longer be able to use "Dim oHTTP As MSXML2.XMLHTTP30," but can
someone give me the correct syntax for what should replace it? I know
I have to start with "Dim oHTTP as object," but beyond that I'm a bit
unsure. The below does not work:

Dim obj As Object

Set obj = CreateObject("MSXML2.XMLHTTP30")


TIA for any help.
 
T

Tom Ogilvy

Excel does not release references if not used. Having references checked
that you don't need invites problems if you distribute the app.

I know nothing about Microsoft XML, but I came up with this which doesn't
raise an error:

Sub Testera()
Dim ohttp As Object
Set ohttp = CreateObject("MSXML2.XMLHTTP.3.0")
Debug.Print ohttp.readyState
Set ohttp = Nothing
End Sub
 
C

Cheer

Excel does not release references if not used. Having references checked
that you don't need invites problems if you distribute the app.

I know nothing about Microsoft XML, but I came up with this which doesn't
raise an error:

Sub Testera()
Dim ohttp As Object
Set ohttp = CreateObject("MSXML2.XMLHTTP.3.0")
Debug.Print ohttp.readyState
Set ohttp = Nothing
End Sub


Thanks, Tom. I suppose I'll just start hacking out references and see
what breaks.

Thank you too for the proper argument for CreateObject to load the XML
v3.0 library. Knowing where to put those two dots made all the
difference.

Don't suppose you know how to do late binding on the Extensibility
library and the HTML object library?
 
B

Bob Phillips

The extensibility library is simple, as you don't need to use Createobject,
like so

Dim VBComp As Object

Set VBComp = ThisWorkbook.VBProject.vbcomponents("Module2")
ThisWorkbook.VBProject.vbcomponents.Remove VBComp

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
T

Tom Ogilvy

Bob answered for the extensibility library

I did a google search on

CreateObject MSXML2.XMLHTTP30

If you create the reference, then look in the object browser, I assume the
first part will be the library name (MSXML2 as an example). I picked the
second from the object, but as you see, it required some alterations. I
would probably search google on CreateObject and the library name alone.
 
B

Bob Phillips

The OP has made a good point though, so if anyone knows such a reference, I
would also like to see it.

Bob
 
C

Cheer

Comments inline.

The extensibility library is simple, as you don't need to use Createobject,
like so

Dim VBComp As Object

Set VBComp = ThisWorkbook.VBProject.vbcomponents("Module2")
ThisWorkbook.VBProject.vbcomponents.Remove VBComp

Thanks, Bob. Nice illustration of adding/removing the object.

Bob answered for the extensibility library

I did a google search on

CreateObject MSXML2.XMLHTTP30

If you create the reference, then look in the object browser, I assume the
first part will be the library name (MSXML2 as an example). I picked the
second from the object, but as you see, it required some alterations. I
would probably search google on CreateObject and the library name alone.

Thank you too, Tom. I will separate the two pieces ("CreateObject" and
the library name) when searching for the OLE Automation syntax.

I envision a catalog of:

Library Name
A. How to invoke it using early binding
1. How to programmatically add the reference
B. How to invoke it using late binding

Or better yet, a VBE tool that converts from early --> late,
flawlessly. Oh, and it removes unneeded references. Would it hurt if
it also made a good cheese danish?

Thanks again to both of you for all of your help. You folks really are
amazing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top