How to add multiple conditions in one line of code

brenton

New Member
Joined
Aug 24, 2011
Messages
33
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")

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:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hello Brenton

I do not understand your worries, but I understand what you want to do.
I am not sure it can be done in 1 go.
If you are worried about lengthy procedures, consider:

Code:
    With ActiveWorkbook.VBProject.VBComponents
        .Remove .Item("AccountDetails")
        .Remove .Item("Async")
        .Remove .Item("BrentSyncButton")
        .Remove .Item("Calculators")
        .Remove .Item("ClearMethods")
    End With

If you are worried about hardcoding a lot of things in VBA and have the module names buried in VBA-coding (as here), consider storing the module names in a (hidden) worksheet, and have a loop through these cells. Each time, call your .Remove method as above.
 
Upvote 0
Ok thanks Wigi! the with does make it a little nicer. Just working on keeping my code nice and concise. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,109
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top