MS Access uses VBA to remove a module from an access file
I am looking for a way to remove a VBA module from an external database file using VBA code. An external file named "myfile.accdb" has a module named "mod1". I would like to remove this module using VBA code in a separate project.
something like this:
OpenDatabase ("myfile.accdb"). Modules ("mod1"). Delete
working code would be very much appreciated as I couldn't find myself and couldn't write my own.
+3
source to share
1 answer
From Ozgrid.com - How to Remove a Code Module
This code will remove the code module.
Sub DeleteThisModule()
Dim vbCom As Object
MsgBox "Hi, I will delete myself "
Set vbCom = Application.VBE.ActiveVBProject.VBComponents
vbCom.Remove VBComponent:= _
vbCom.Item("Module1")
End Sub
So you need a reference to Visual Basic for Application Extensibility and also you need to trust access to the VB editor
So the above code will get you started, however you need to refer to an external file as an application
+2
source to share