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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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,216,098
Messages
6,128,811
Members
449,468
Latest member
AGreen17

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