Link to home
Start Free TrialLog in
Avatar of Samantha Moore
Samantha MooreFlag for United States of America

asked on

Linking Office Programs with VBA

I have an application written in MSAccess 2010.  It is a large and complex application and it works fine.  I distribute this application with the MSAccess runtime environment.  This environment only contains the Access runtime engine and no additional MS Office software.

I have a user request to add a feature to dynamically create an MSExcel spreadsheet with data from the application.  To include this feature I have to link the Microsoft Excel 14.0 object library so that calls to Excel.Application, and all the workbook, sheet, and cell functionality can be used.

The problem that I have is that if I include this library, then the software won't run on machines that have NO excel installed, even if I don't use this functionality.  It is just a matter of the dynamic linking at load time.  Even more so, if the user has excel 2007, 2003, or any other than 2010, the code won't load either.

So, what I'm looking for is a way to handle load time errors, just like I can handle runtime errors with an "on error" statement.  If I can handle these load time errors, then I can add conditional code that will allow calls to the appropriate routines if needed/allowed/desired.

Anybody have a clue?
Avatar of Norie
Norie

You don't need the reference if you use late-binding, so that would take care of the version problem.

Not sure about how you would handle the case when a user doesn't have Excel installed.

Actually what you could do is something like this.
Dim xl As Object

    On Error Resume Next
    Set xl = CreateObject("Excel.Application")
    On Error Goto 0

    If xl Is Nothing Then
        MsgBox "This function requires Excel to be installed and available.
        Exit Sub
    End If

Open in new window

Avatar of Samantha Moore

ASKER

Awesome!  How to I use late binding?
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Awesome!  Thank you so much!