Delete Userforms In All Workbooks

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,060
Can anyone please provide a script that will delete all userforms in all open workbooks except for the workbook it is being run from, it can not be a code that needs to be pasted into a reference via Alt T, it needs to be able to be run as a macro in a userform.

I was provided the following code but it cliches on this line.

code:
For Each VBComp In VBProj.VBComponents

full code follows

code:
Sub RemoveAllUserForms()
Dim VBComp As Object
Dim VBProj As Object

For Each VBProj In Application.VBE.VBProjects
For Each VBComp In VBProj.VBComponents
If VBComp.Type = 3 Then
VBProj.VBComponents.Remove VBComp
End If
Next VBComp
Next VBProj

End Sub
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Misca

Well-known Member
Joined
Aug 12, 2009
Messages
1,671
It seems to error because some of the running VBA projects on my computer are protected.

I added the line
Code:
On Error Resume Next
after the Dim lines and it seems to work.

What the line does is it tells the macro to ignore errors.
 

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
Isn't it On Error GoTo 0?

I really have no idea what it exactly does but I saw it alot so maybe...
 

Watch MrExcel Video

Forum statistics

Threads
1,122,912
Messages
5,598,828
Members
414,260
Latest member
joishe

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
Top