delete userforms in vba

  • Thread starter Thread starter malpropio
  • Start date Start date
M

malpropio

Hey everyone,
I'm trying to get rid of a form I created in a project so I can
import another one which has the same name.
But so far I havent been able to find a way to do it.
So please let me know if thats possible and if not what would be the
solution to my problem.

Thx
 
In the code window, right-click on the user-form name in the left column and
select "Remove Userform".
 
in the project explorer in the VBE, right click on you userform entry under
the appropriate workbook and select remove.
 
Thk u Tom and Jim,
But I don't know if its because I'm using the vb code editor of excel
but when I right click on the userform in the project explorer it does
not give me the choice to delete it.

malpropio
 
If you want to do this by code, set a reference to the VBA 5.3 Extensibility
Library (in VBA, go to the Tools menu, choose References, and check
"Microsoft Visual Basic For Applications Extensibility Library 5.3"). Then
use code like

Sub DeleteForm()
Dim VBComps As VBIDE.VBComponents
Dim VBComp As VBIDE.VBComponent
Set VBComps = Workbooks("Book1.xls").VBProject.VBComponents
Set VBComp = VBComps("UserForm1")
VBComps.Remove VBComp
End Sub

See www.cpearson.com/excel/vbe.htm for more details and example code.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
Or, simpler, without needing a library reference:

Sub DeleteForm()
With Workbooks("Book1.xls").VBProject.VBComponents
.Remove .Item("UserForm1")
End With
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
I didn't say to right click on the userform itself. Re read my post.

All actions are performed in the project explorer window (defaults to the
upper left of the VBE). You right click on the name of the Useform as
shown in the project explorer.
 
Back
Top