I am currently working on a project where I am unable to verify that all modules are installed. There is a growing group of modules being used for common functions for programs I work with. I have tried some solutions on the web which I couldn't use as I am unfamiliar with Activeworkbook.VBProject.VBComponents()
methods.
It was mentioned that I should check tools reference for Microsoft Visual Basic For Applications Extensibility and I checked that with no result. Any help would be appreciated. :)
References:
https://www.devhut.net/2010/12/09/ms-access-vba-determine-if-a-module-exists/
here is my code:
Option Explicit
Public Function Is_Module_Loaded(name As String) As Boolean
Dim Module As Object
Dim Module_Name As String
Module_Name = name
Is_Module_Loaded = False
On Error GoTo errload
Set Module = ActiveWorkbook.VBProject.VBComponents(Module_Name).CodeModule
Is_Module_Loaded = True
If (0 <> 0) Then
errload:
MsgBox ("MODULE: " & Module_Name & " is not installed please add")
Stop
End If
End Function
When Running the Code I don't get any error that is very helpful excluding my own which is reporting wrong saying my module is absent when it isn't.
ThisWorkbook
, and using the VBIDE API to replace the module with it if it exists in the target project, or add it if it doesn't. Now, instead of a hand-crafted error message that's actually suppressing the would-be helpful error, considerMsgBox Err.Description
. What's the actual error? – Mathieu GuindonMsgBox Err.Description
part I am unfamiliar with this. I believe in the original I have no error even without my custom error message. also I was unable to figure out the VBIDE API but the idea of the code loading the modules from a location would be very useful. – Zackd41pro