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
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Misca

Well-known Member
Joined
Aug 12, 2009
Messages
1,733
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...
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,990
Messages
5,856,679
Members
431,828
Latest member
kARTIK12345

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