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.



Answer this question

Command Buttons (Delete, Run, and Close)

  • David Joyce

    Perfect!! Thank you so much!
  • Shawnk

    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



  • Javahar

    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


  • robertje

    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


  • Command Buttons (Delete, Run, and Close)