dll files in Excel VBA or ADO

G

Guest

Can you "#include" a dll file in an Excel routine using VBA or ADO? I am
trying to make a routine that a user can copy and paste, without any other
efforts. Right now they have to select two references for the routine to
work. I can not find the equivalent of #include for VBA/ADO. Thank you.

Brent
 
T

Tim Williams

'Early binding
Dim oRS as New ADODB.Recordset '(the lazy way using New)


vs

'late binding - does not require VBA Project reference to ADO library
Dim oRS as Object
set oRS = CreateObject("ADODB.Recordset")
 
G

Guest

Okay I already have it as the lazy way, but I still have to go to
Tools->References and pick A.D.O. 2.8 library. Is there a way that I don't
have to go to Tools->References and do this for each new workbook?

Brent
 
G

Guest

You want to use Late Binding as demonstrrated by Tim. Early binding binds the
dll at design time where as Late Binding binds the dll at run time. So use...

'late binding - does not require VBA Project reference to ADO library
Dim oRS as Object
set oRS = CreateObject("ADODB.Recordset")
 
G

Guest

I am still having to select the library, otherwise the VBA project will not
run and stops at:

rs.Open "table1", cn, adOpenKeyset, adLockOptimistic, adCmdTable
 
T

Tim Williams

You'll need to replace those named constans with their actual values. Look them up in the ObjectBrowser (with a reference to ADO
added temporarily)

Eg:
adOpenKeyset = 1
adLockOptimistic = 3
adCmdTable = 2



rs.Open "table1", cn, 1, 3, 2
 

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