Check if Component Exists


Home           Programming       Favorites      

The function below will check for the existence of a specific vbComponent.

Forms and Modules are common vbComponents.

Function DoesComponentExist( _ 
ModuleName As String) As Boolean
   Dim VBAEditor As VBIDE.VBE
   Dim VBProj As VBIDE.VBProject

   Set VBAEditor = Application.VBE
   Set VBProj = VBAEditor.ActiveVBProject

   On Error Resume Next
   DoesComponentExist = _ 
Len(VBProj.VBComponents(ModuleName).Name) <> 0

End Function
The procedure below will call the function above.
Thise procedure will check to see if Module 1 exists in the application.
Sub CallDoesComponentExist()

   MsgBox DoesComponentExist("Module1")

End Sub