In one of my classes, I have a global private variable:
Private ie as InternetExplorerMedium
This is an object from the Microsoft Internet Controls Reference. The code compiles successfully assuming the reference is already enabled.
However, one piece of my code is actually enabling these references in the first place. I'm writing an excel add-in that will enable these references, do the main code block, then disable these references at the end. Relevant (pseudo-)code:
Private Sub addReferences()
For Each reference...
Application.VBE.ActiveVBProject.References.AddFromFile <reference>
Next reference
End Sub
Let's assume the user has none of these references enabled in the first place. The script will then not compile, stating that the "User-defined type" InternetExplorerMedium is not defined. The error makes sense, of course.
Is there any way to avoid this compile error, knowing that the code will initially enable these references and thus the objects will exist? I'm expecting the answer to be no, but what alternatives are there?