How to Delete Another WorkBook Macros
Hi again,
The code below does for me what you describe. You may need to go to the VBA
Editor's menu ToolsReferences and set a reference to 'Microsoft Visual
Basic for Application Extensibility #.#' library.
Regards,
KL
Sub Remove_Modules()
Dim arrMod As Variant
Dim prOld As VBIDE.VBProject
Dim mdNew As VBIDE.CodeModule
Set mdNew = Workbooks("HSA template 1.xls").VBProject. _
VBComponents("AllDataYieldCrunch").CodeModule
Set prOld = Workbooks("HSA template 2.xls").VBProject
arrMod = Array("SortData", "CrunchData")
mdNew.InsertLines mdNew.CountOfLines + 1, Chr(13)
For i = LBound(arrMod) To UBound(arrMod)
With prOld.VBComponents(arrMod(i)).CodeModule
COL = .CountOfLines
For j = 1 To COL
mdNew.InsertLines mdNew.CountOfLines + 1, .Lines(j, 1)
Next j
mdNew.InsertLines mdNew.CountOfLines + 1, Chr(13)
prOld.VBComponents.Remove prOld.VBComponents(arrMod(i))
End With
Next i
End Sub
|