Use Late Binding to determine what reference to add?

Rx_

Nothing In Moderation
Local time
Today, 06:30
Joined
Oct 22, 2009
Messages
2,803
Can an Application check the Workstation for Excel Version using late binding, then use the results for code to set a (Tools Reference) Reference to that Excel version and continue the VBA code using early binding?
- Just wondering if anyone has tried that? was it successful?

e.g. send code to a client workstation, determine if it is Excel 2000 or Excel 2010, - take the result of that - Create a reference to that Excel version - then continue with Early Binding code. Thus avoiding the slow processing and painful conversion of late binding.

Was looking at some code along that line.
Also was wondering if WMI might be used to make that determination for older versions of Excel / OS?

Also uploaded a sample MDB using WMI titled:
WMI(Windows Management Instrumentation) using VBA instead of scripts.
Located At: http://gainingaccess.net/GainingAccess/FreeDownloads.aspx#WMISampleDb
This actually works on my workstation (Win 7 32 bit with Office 2010)
It is the only working sample of WMI that I found. Lots of code I have yet to go through.


For consideration:
Code:
' insert into a public module in Excel. 
Public Sub ReturnExcelVersion()
    If Application.Version = "12.0" Then
        MsgBox "You are using Excel 2007."
    ElseIf Application.Version = "11.0" Then
        MsgBox "You are using Excel 2003."
    ElseIf Application.Version = "10.0" Then
        MsgBox "You are using Excel 2002."
    ElseIf Application.Version = "9.0" Then
        MsgBox "You are using Excel 2000."
    ElseIf Application.Version = "8.0" Then
        MsgBox "You are using Excel 97."
    ElseIf Application.Version = "14.0" Then
        MsgBox "You are using Excel 2010 hey, what happened to Version 13.0 ??"
    End If
MsgBox "Microsoft Excel is using " & Application.OperatingSystem
End Sub
 

Attachments

You don’t seem to be saying where the resultant early bound code will be running; Excel or Access?

Late binding might be slow but I don’t think I have ever seen anybody, including Microsoft, quantify it.

Painful conversion to late binding only exists for those who have always taken the easy way out.
It should be a matter of course to remove external dependencies.

Code:
Option Compare Database
Option Explicit


Private Sub Form_Open(ByRef intCancel As Integer)
    Dim ref As Reference

    For Each ref In References
        If InStr(ref.FullPath, "Excel.exe") Then
            References.Remove ref
        End If
    Next ref

    References.AddFromFile SysCmd(acSysCmdAccessDir) & "Excel.exe"
    
End Sub


Private Sub Form_Load()
    Dim X As Excel.Application
    
    MsgBox "Survived early bound reference change."

End Sub

Hint: Don’t do it, it will not work in an MDE file.

Chris.
 

Users who are viewing this thread

Back
Top Bottom