delete userforms in vba

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
 
G

Guest

In the code window, right-click on the user-form name in the left column and
select "Remove Userform".
 
G

Guest

in the project explorer in the VBE, right click on you userform entry under
the appropriate workbook and select remove.
 
M

malpropio

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
 
G

Guest

You must right click on the form you want to remove, not just in the project
window.
 
C

Chip Pearson

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)
 
C

Chip Pearson

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)
 
T

Tom Ogilvy

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top