Thread: Late Binding
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Late Binding

Jake's reasoning is very sound on this. I have posted a worked example
previously (using Outlook) on this same topic. You can read it at
http://tinyurl.com/2qern

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jake Marx" wrote in message
...
Hi Cindy,

Not sure what feedback you already got on this, but I'll give it a shot.
Typically, I develop all code using Early Binding (set a reference, Dim
objects explicitly, use named constants from libraries). Once everything

is
working, I modify my project to use Late Binding. To do this, you need

to:

1) Get values of all named constants from libraries (in your case, ADO and
Outlook). For example, if your code has adStateOpen in it, you need to

get
the actual value of this constant so that when you remove the reference to
ADO, your project will work. If you did not replace the named constant

with
its value, you would get a syntax error (if you use Option Explicit) or
unexpected results (as the constant will evaluate to zero when the library
reference is removed). The easiest way to get the value of a constant is

to
print it to the Immediate Window:

?adStateOpen
1

Obviously, you'll want to do this while the reference is still set.

2) Replace all explicit object types with Object. And replace all Set x =
New y with a CreateObject call. So if you have:

Dim cnMain As ADODB.Connection
Dim cdEmp As ADODB.Command

Set cnMain = New ADODB.Connection
Dim cdEmp = New ADODB.Command

You would replace this with:

Dim cnMain As Object
Dim cdEmp As Object

Set cnMain = CreateObject("ADODB.Connection")
Set cdEmp = CreateObject("ADODB.Command")


That should do it. If you have any further questions or don't understand
something here, let us know.


--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Cindy wrote:
I have an Excel 2000 application that uses references to
Active X Data Objects 2.5 and Outlook 9 Object library. I
need to instill late binding because users have different
versions of MSOffice and this causes a problem with the
library reference files. I did post before on this and
received some feedback, websites, etc. but I am confused
especially on how to "late bind" the ActiveX Data Objects
2.5 library file. Please help if you can.

Thank you.

Cindy