PDA

View Full Version : Modifying VBE references causing problems in a class module?



kmahlendorf
05-10-2006, 02:52 PM
After running a simple routine which adds a reference to a type library, subsequent event-triggered routines in my class module no longer are executed. For example, I can drop a MsgBox command in the App_WorkbookBeforeClose section and it never executes. If I rem out the code that calls the "offending" routine, everything goes back to working just fine.

I've tried housing these routines in the class module, a regular module, and ThisWorkbook - same problem each time. What is going on and how can I fix it?

Here's the code that causes the problem:



Public Sub RemoveReferences()
On Error Resume Next
Dim xObject As Object
Set xObject = ThisWorkbook.VBProject.References.Item("spsswin")
ThisWorkbook.VBProject.References.Remove xObject
On Error GoTo 0


End Sub
P.S. One other routine causes the same problem, but it deals with adding a type library reference...so I know it has something to do with modifying those references...just can't figure out what.



Public Sub RemoveReferences()
ThisWorkbook.VBProject.References.AddFromFile ("C:\Program Files\SPSS14\spsswin.tlb")

End Sub