automatically load an object library in real time

D

dtshedd

I have read many articles on the same subject but the discussions
about early/late binding are a bit over my head.

I am looking for a simple way to check if the microsoft internet
controls library is loaded and if not load it..

i also noted that at work this library is available (tools-references)
but at home microsoft internet controls does not even show in my list.
(although HTML object library is on the list)

i am using excel 2002

tia
 
C

Chip Pearson

You can programmatically add the reference with the following code:

Sub LoadInternetLibrary()
On Error Resume Next
ThisWorkbook.VBProject.References.AddFromGuid _
"{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 1, 1
End Sub

The On Error statement causes VBA to ignore the error that would arise
if the library is already referenced.

HOWEVER... If your code declares variables of the types defined within
this library, the code will not compile and thus the code to add the
reference won't get executed. There is really no way to declare
variables whose types are defined in a library that isn't loaded when
the code is written and will not be loaded until run time.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
J

Joel

the DLL name for the library is IEFRAME.DLL. Yo can use this code to check
if the library is loaded.

Sub checkLibrary()

found = False
For Each lib In Application.VBE.ActiveVBProject.References
BaseName = lib.fullPath
BaseName = Mid(BaseName, InStrRev(BaseName, "\") + 1)
BaseName = UCase(BaseName)
If BaseName = "IEFRAME.DLL" Then
found = True
Exit For
End If
Next lib
If found = True Then
MsgBox ("Library IEFRAME.DLL was loaded")
Else
MsgBox ("Library IEFRAME.DLL was not loaded")
End If
 
C

Chip Pearson

Joel,

That is a fine, but the assumption is that the user wants to actually
use the library, not merely have a reference to it. And that implies
that there will be variables declared that are defined in the library.
Prior to running the CheckLibrary function, the compiler will choke on
any variables whose type is defined in the (presently unreferenced)
IEFRAME.dll.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
J

Joel

I just showed code how to determine if the library was selected as a
reference. I assumed that your code would be used to add the library if
Found was false. I just want to show tia that you can get all the defined
references in VBA.
 

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