Libraries in Excel

B

Brent

I am trying to bystep making each user go to Tools->References on the toolbar
in the visual basic editor, to check the box to include the ADO 2.8 Library.
Using early and/or late binding seems to do nothing as far as "checking the
box" for the user. Is there coding, since you cannot do macros for this, to
include the library? Like in C++ you would use the statement #include to add
a library, what do you have to do for either VBA or ADO?? Thank you.

Brent
 
J

Jim Rech

If you "check the box" and save the file and another user opens the file,
the box will still be checked. The only problem that can occur is if the
referenced library does not exist on the other user's machine. In that case
an untrappable error will occur. If that's a possibility use late binding.
Late binding does not literally "check the box" but it doesn't have to. It
does establish the reference in code.

--
Jim
|I am trying to bystep making each user go to Tools->References on the
toolbar
| in the visual basic editor, to check the box to include the ADO 2.8
Library.
| Using early and/or late binding seems to do nothing as far as "checking
the
| box" for the user. Is there coding, since you cannot do macros for this,
to
| include the library? Like in C++ you would use the statement #include to
add
| a library, what do you have to do for either VBA or ADO?? Thank you.
|
| Brent
 
V

Vergel Adriano

maybe this will give you some idea... this is for Excel 2003. Create a new
workbook and paste the code in the Thisworkbook code module. Save it and
then open the workbook. It would add a reference to ADO Library 2.8 on open.
One caveat to this is that you must permit access to the Visual Basic
Project. Tools->Macro->Security, in the Trusted Publishers tab, check "Trust
Access to Visual Basic Project".


Option Explicit

Private Sub Workbook_Open()

If Not IsADOReferenced Then
ThisWorkbook.VBProject.References.AddFromGuid
"{2A75196C-D9EB-4129-B803-931327F72D5C}", 2, 8
End If

Test_ADO
End Sub


Private Function IsADOReferenced() As Boolean

Dim strGUID As String
Dim r As Object

strGUID = "{2A75196C-D9EB-4129-B803-931327F72D5C}"

IsADOReferenced = False
For Each r In ThisWorkbook.VBProject.References
If r.GUID = strGUID Then
IsADOReferenced = True
Exit For
End If
Next r

End Function

Private Sub Test_ADO()
Dim conn As New ADODB.Connection
MsgBox conn.Version
End Sub
 
B

Brent

r.GUID produces an error. If I do late binding this line produces an error:

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

if I take out evrything after cn then I get an error at rs.AddNew. Any
suggestions?? Thank you!!

Brent
 
B

Brent

just did late binding and change adOpenKeyset, adLockOptimistic, adCmdTable
to 1,3,&H2 and it works now. Thank you all.
 
B

Brent

Brent said:
I am trying to bystep making each user go to Tools->References on the toolbar
in the visual basic editor, to check the box to include the ADO 2.8 Library.
Using early and/or late binding seems to do nothing as far as "checking the
box" for the user. Is there coding, since you cannot do macros for this, to
include the library? Like in C++ you would use the statement #include to add
a library, what do you have to do for either VBA or ADO?? Thank you.

Brent
 

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