Hi KeepITCool,
Thanks for that and I will give that a go.
Not that it may be necessary, but would it set a reference to say 2.8 if the
registry key:
HKEY_CLASSES_ROOT\MDACVer.Version\CurVer\
says 2.7?
Do you see any pitfalls with my suggested approach?
I want to avoid late binding and I don't think I have to.
RBS
"keepITcool" wrote in message
.com...
I just wrote this this. Works on my machine but no guarantees
for misc client setups..
Approach:
find the inprocserver for the current version of a com object in the
registry. Use that file to create the reference in VB.
Sub Demo()
ThisWorkbook.VBProject.References.AddFromFile _
GetLibrary("adodb.connection")
End Sub
Function GetLibrary(sProgID$) As String
Dim oReg As Object, sDat$
Const HKCR = &H80000000
Set oReg = GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\.\roo t\default:StdRegProv")
oReg.getstringvalue _
HKCR, sProgID & "\CLSID", vbNullString, sDat
oReg.getstringvalue _
HKCR, "CLSID\" & sDat & "\Inprocserver32", vbNullString, sDat
GetLibrary = sDat
End Function
--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam
RB Smissaert wrote in
Yes, late binding is an option, but it has drawbacks as well.
My idea to tackle this is as follows:
Save the wb (an .xla file) with a reference to a low version, 2.1
In the Workbook_Open event remove this reference and loop through
the possible versions down from 2.8 to 2.0 and try adding them.
If successful then exit this loop.
This works fine, but I just need to know a few more versions.
I could read the version from the registry:
HKEY_CLASSES_ROOT\MDACVer.Version\CurVer\
but I have noticed that on my machine this gives me 2.7, but I can use
2.8, so running the loop might be better.
The trouble with ADO is that if I save with say 2.1 and the target
machine has a higher version then that higher version won't be
automatically used as the lower versions can still be present. Maybe
there is no harm to use say 2.1 if the user has 2.8, but I might as
well go for the higher version and I think my method will work.
RBS
"AA2e72E" wrote in message
...
I don't think I understand why you want to use the GUID, the least
intuitive bit of information about objects.
The latest version of ADO is 2.8.
If you use late binding, you automatically pick up the last
installed version, e.g.
Set ADOC = CreateObject("ADODB.Connection")
Set ADORS = CreateObject("ADODB.Recordset")
So, if you ran the code on a PC with 2.8, you will reference 2.8
and if you ran the same code on a PC with 2.6 only, you will
reference 2.6.
If you hardcode the GUID, all PCs will have to have the same
version as on the development PC for your code to work.