PDA

View Full Version : Addin References



mapkn
03-03-2009, 03:29 PM
Hello All,

I have an xla which is to be used with a particular Excel workbook. There are also various VBA modules which should reference this xla in order to function properly.

In order to make sure that the correct xla is being referenced by the VBE, I want to:
1) remove all the existing references to the VBA project (even if they are not 'MISSING' and
2) add reference to this particular xla when the workbook is opened (using the Workbook_Open procedure).

I know how to part 2), but am having problems with part 1). I'm sure this must be something someone has seen before so would be very grateful for any help.

Regards,

Mitul

Digita
03-03-2009, 09:11 PM
Hi Mitul,

I don't think XL would allow complete removal of ALL references. The following code removes all except VBA and XL Object library references:

Sub Test()
On Error Resume Next
For i = ThisWorkbook.VBProject.References.Count To 1 Step -1
Set Ref = ThisWorkbook.VBProject.References.Item(i)
ThisWorkbook.VBProject.References.Remove Ref
Next
Set Ref = Nothing
End Sub

Rgds


kp

mapkn
03-04-2009, 06:09 AM
Thanks for your help.

I had not realised that I would not be able to remove all references and so did not have any error handler in my code. When I add that it works fine.

Thanks again.

Mitul