how can i specify the modules i want removed and then also import that same list without having a line for each one.
ex currently doesnt work:
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents(("AccountDetails"), ("Async"), ("BrentSyncButton"), ("Calculators"), ("ClearMethods"))
instead of
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("AccountDetails")
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("Async")
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("BrentSyncButton")
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("Calculators")
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("ClearMethods")
ex currently doesnt work:
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents(("AccountDetails"), ("Async"), ("BrentSyncButton"), ("Calculators"), ("ClearMethods"))
instead of
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("AccountDetails")
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("Async")
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("BrentSyncButton")
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("Calculators")
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents("ClearMethods")
Code:
Sub ImportModules()'http://www.mrexcel.com/forum/excel-questions/380219-copy-module-external-workbook.html
Application.EnableEvents = False
Dim i As Integer
i = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Do While Worksheets(1).Cells(i, 1) <> ""
Set objFile = objFSO.GetFile(Worksheets(1).Cells(i, 1))
Workbooks.Open objFile, , False
'Remove Module or it will keep the old one
ActiveWorkbook.VBProject.VBComponents.Remove ActiveWorkbook.VBProject.VBComponents(("AccountDetails"), ("Async"), ("BrentSyncButton"), ("Calculators"), ("ClearMethods"))
'VBComp ActiveWorkbook.VBProject.VBComponents("AccountDetails")
'Bring in new bas files
ActiveWorkbook.VBProject.VBComponents.Import ActiveWorkbook.VBProject.VBComponents(("AccountDetails"), ("Async"), ("BrentSyncButton"), ("Calculators"), ("ClearMethods"))
ActiveWorkbook.Save
ActiveWorkbook.Close
i = i + 1
Loop
Application.EnableEvents = True
MsgBox ("successfully updated files")
End Sub
Last edited: