LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default References to XLA files

Hi!

This question has been asked before and today I am facing the same
problem. Luckily by browsing this forum and using a bit of intuition I
managed to find a solution to this common problem.

If you use the code below you should be able to assign a relative path
to your xla (add-in) file. This will allow you to distribute your
excel files more easily (e.g. by providing your xls files & and
add-ins under one folder). So, here is the code (to be saved in "This
workbook"):

Private Sub Workbook_Open()

Dim response As Integer

On Error Resume Next
If ActiveWorkbook.VBProject.References("<ADDIN NAME").IsBroken _
Then
On Error GoTo Err_handle
ActiveWorkbook.VBProject.References.AddFromFile _
ActiveWorkbook.Path & "\<YOUR ADDIN PATH AND FILENAME"
End If

Exit Sub

Err_handle:
response = MsgBox("Could not Reference ""xxx.xla""" & _
vbCr & """xxx.xla"" must be under directory yyy", _
vbOKOnly + vbExclamation)

End Sub

Description:
Because the code is in "ThisWorkbook" object, it will be run whenever
the workbook is opened.

If the referenced addin is available the "if" statement will do
nothing and the sub will exit. On the other hand, if the addin is not
available, the "if" statement will generate an error. However because
the first "on error" statement is placed just before, it will try to
re-attach the addin by using the "addFromFile" method of the
References collection. In turn, if this fails the error handler will
catch it (thanks to the second "On error" statement) and displays the
error message.

Possible improvements
Include all the addins under a given folder (e.g like winamp behaves
with plugins).

Regards,

Olivier
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling Data, References and Flat Files GF08 Excel Discussion (Misc queries) 1 November 19th 09 10:19 PM
Macro for saving files where title is made from cell references [email protected] Excel Discussion (Misc queries) 1 May 12th 07 06:23 PM
Cell References Between sheets or Files Not Working MM Phil Excel Discussion (Misc queries) 3 February 1st 07 10:01 PM
Can a workbook be locked against change to cells containing references to other files? az94 Excel Worksheet Functions 0 March 28th 06 08:26 PM
References to external XLS files goto_guy Excel Discussion (Misc queries) 1 January 17th 06 04:34 PM


All times are GMT +1. The time now is 03:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"