Reference Object Library within user defined function

conradin.flurin

New Member
Joined
Dec 20, 2012
Messages
2
Hello

I have written a UDF (Usder defined function), which accesses a access database and runs an SQL call in it and returns the data item.

I'd like to automatically reference the "Microsoft ActiveX Data Objects Library" I use for this UDF and I have written a sub that does this

Code:
Sub reference_ADODB_library()
    Dim i As Integer
    With ActiveWorkbook.VBProject
        For i = 1 To .References.Count
            If .References(i).Name = "ADODB" Then
                Exit Sub
            End If
        Next
        .References.AddFromGuid "{B691E011-1797-432E-907A-4D8C69339129}", 6, 1
    End With
End Sub

This Sub works alright, however my UDF function fails unless I first reference the object library manually before using the UDF.

Any thoughts on this?

Cheers!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Why don't you late bind your UDF instead?
 
Upvote 0
Why don't you late bind your UDF instead?


Hello Rory

The reason I didn't use late binding was because the this part of my code failed

Code:
    With cnt
        .Open (stConn)
        .CursorLocation =  [FONT=Arial][SIZE=2]adUseClient[/SIZE][/FONT]
    End With

but of course, I can just use the actual constant

Code:
    With cnt
        .Open (stConn) 
        .CursorLocation =  3
    End With


Thank you for taking me out of the tunnel

Cheers
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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