In addition to this answer , which is a bulletproof solution to solve these kinds of problems, but which is rather difficult to implement, you can also write some code that should be run when your VBA application starts, checking the collection of "links" of the "application" object. Then you can check (1) if the required files (dll, ocx, tlb) are available on the computer, and (2) if the link can be created (application.references.addFromFile ...).
Be careful: declarations of objects that may be link dependent, for example:
Dim cat as ADOX.catalog
compilation will fail if the link is not active when the corresponding module is “compiled”. Then I advise you to isolate your "link checking procedure" in the launcher (equivalent to "autoexec"), which deals only with VBA and the application's underlying objects. Check it with help files (example: in Access, the default links that can be used without external links are VBA, Access, and DAO).
EDIT:
in case external links depend on another software package and (1) cannot be distributed with the MSI file or (2) may have several versions, I think that "reference.addFromFile" is the only solution that can be applied. Example:
- You have a run-time client for a VBA / Access application that should reference Word (file msword.olb).
- For licensing issues, you cannot freely distribute this file using your msi package
- olb file can be either XP version or newer
Our solution is to have 2 tables in the client access file. The list lists all the links that you need to check or add at startup (Word will be one of them), and the other lists all possible locations of the file (depending on whether the user has a version of "office11" or a newer one), with one to many relationships between two tables.
So, a combination between msi packages and code-based management might be the best strategy:
- msi is great for distributing independent dlls or other files completely “embedded” in your application, such as ActiveX controls (for example, scanner controls, report or file viewers, etc.).
- code is the best solution in which your application will have to communicate with other applications (word, excel, outlook, etc.) that may exist in different versions on your user machines.
Philippe grondier
source share