Command Buttons (Delete, Run, and Close)

Ok I have a userform that asks if you would like to calculate now. There are two command buttons on the form, one says Yes the other says No.

I need the form to automaticlly open when the user opens the workbook.

When the user clicks on No I want the form to close.

When the user clicks on Yes I want it to delete the last worksheet in the workbook and then run a process (called process).

One is this possible (I know the No button is)? and two how do I get it to work?

Thanks for any help or ideas.

[537 byte] By [TigerPhoenix] at [2007-12-23]
# 1

In the WorkBook Code Module:

Private Sub WorkBook_Open()

Userform1.Show

Enf Sub

In the form Code Module

Private CommandNo_Click()

unload userform1

End Sub

Private CommandYes_Click()

Application.DisplayAlerts = False
Worksheets(Worksheets.Count).Delete
Application.DisplayAlerts = True
Call Process
End Sub


Sub Process()
' process code
End Sub

Chas

ChasAA at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 2
Perfect!! Thank you so much!
TigerPhoenix at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 3

I used the first bit:-

Private Sub WorkBook_Open()

Userform1.Show

End Sub

> but it dodnt work for me! Comes up with hte debug prompt. The name 'UserForm1' is the same.

I stuck what else to check for!!

Thanks

Matt

MatthewBalch at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 4

What your userform name, is it actually "Userform1" or have you called it something else. In the VBE environment, if you click on the "Forms" section, what are the userforms present. Or it seems you have a duplicate name somewhere.

Chas

ChasAA at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...