How do I use late binding to avoid references libraries?

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
The compile error occurs because of a Dim statement:

"Dim A As Connection"

Is there a way to avoid this without manually setting the reference on every PC?
 
Upvote 0
Removing the specific references to "Connection" and "Recordset" (replacing them with generic objects) avoids the compile error.

This only leaves me with one question, which is why the exact same code produces no compile error when it's executed from a separate workbook.
 
Upvote 0
I'm trying to avoid manually setting references because there are a lot of machines here and they're not all setup at the same time, so it would be a major hassle (unless it could be done programmatically)? Even then the compile error would probably happen anyway before the programmatic solution could trigger, as soon as the workbook opened.

But supposedly there's a way to solve the problem using 'late binding'. I have no clue what that is.
 
Upvote 0
It's this:
Code:
Dim cn As Object, rs As object
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
 
Upvote 0
What code?

Kind of hard to give specific help with it without seeing it.
 
Upvote 0
Are you saying late binding is using generic "Object" data types for all objects?
 
Upvote 0
I'm trying to avoid manually setting references because there are a lot of machines here and they're not all setup at the same time, so it would be a major hassle (unless it could be done programmatically)? Even then the compile error would probably happen anyway before the programmatic solution could trigger, as soon as the workbook opened.

But supposedly there's a way to solve the problem using 'late binding'. I have no clue what that is.

Late binding is done by using the CreateObject or GetObject Methods to get a reference to a COM object as opposed to setting a reference to the COM Class and using the New Keyword . Late binding is slower and you loose the Intelsense functionality but it is more flexible... and of course, you need to declare all the variables as generic Object
 
Upvote 0
Jafar, would you please give me an example of each?


Norie: Posted the wrong thing, I will have to post it in a little while.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,835
Members
452,947
Latest member
Gerry_F

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