+ Reply to Thread
Results 1 to 5 of 5

Need some help with Exit Event

  1. #1
    Matt
    Guest

    Need some help with Exit Event

    Hi All- I've got an exit button in a user form that I want to
    accomplish the following with when clicked-
    1. Prompt the user to see if they want to save the form and associated
    workbook.
    2. If yes to save then ask to save as and where.
    3. Exit form and excel.

    Presently I have the following code associated with the button.
    Obviously it's inoperable at this point. I've searched quite a bit to
    find some similiar code, without much luck. Any help would be greatly
    appreciated. Thanks.

    Private Sub BtnExit_Click()
    End Sub


  2. #2
    Chip Pearson
    Guest

    Re: Need some help with Exit Event

    Matt,

    Try something like

    Private Sub btnExit_Click()

    Dim FName As Variant
    FName = Application.GetSaveAsFilename(, "Excel Files
    (*.xls),*.xls")
    If FName = False Then
    Exit Sub
    End If
    ThisWorkbook.SaveAs Filename:=FName
    Me.Hide
    Application.Quit
    End Sub


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com




    "Matt" <mlaipple@yahoo.com> wrote in message
    news:1112208878.876736.219640@o13g2000cwo.googlegroups.com...
    > Hi All- I've got an exit button in a user form that I want to
    > accomplish the following with when clicked-
    > 1. Prompt the user to see if they want to save the form and
    > associated
    > workbook.
    > 2. If yes to save then ask to save as and where.
    > 3. Exit form and excel.
    >
    > Presently I have the following code associated with the button.
    > Obviously it's inoperable at this point. I've searched quite a
    > bit to
    > find some similiar code, without much luck. Any help would be
    > greatly
    > appreciated. Thanks.
    >
    > Private Sub BtnExit_Click()
    > End Sub
    >




  3. #3
    Bob Phillips
    Guest

    Re: Need some help with Exit Event

    But be aware that the data entered into the userform is not saved, next time
    it will open as designed.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Chip Pearson" <chip@cpearson.com> wrote in message
    news:ed8$auVNFHA.1884@TK2MSFTNGP15.phx.gbl...
    > Matt,
    >
    > Try something like
    >
    > Private Sub btnExit_Click()
    >
    > Dim FName As Variant
    > FName = Application.GetSaveAsFilename(, "Excel Files
    > (*.xls),*.xls")
    > If FName = False Then
    > Exit Sub
    > End If
    > ThisWorkbook.SaveAs Filename:=FName
    > Me.Hide
    > Application.Quit
    > End Sub
    >
    >
    > --
    > Cordially,
    > Chip Pearson
    > Microsoft MVP - Excel
    > Pearson Software Consulting, LLC
    > www.cpearson.com
    >
    >
    >
    >
    > "Matt" <mlaipple@yahoo.com> wrote in message
    > news:1112208878.876736.219640@o13g2000cwo.googlegroups.com...
    > > Hi All- I've got an exit button in a user form that I want to
    > > accomplish the following with when clicked-
    > > 1. Prompt the user to see if they want to save the form and
    > > associated
    > > workbook.
    > > 2. If yes to save then ask to save as and where.
    > > 3. Exit form and excel.
    > >
    > > Presently I have the following code associated with the button.
    > > Obviously it's inoperable at this point. I've searched quite a
    > > bit to
    > > find some similiar code, without much luck. Any help would be
    > > greatly
    > > appreciated. Thanks.
    > >
    > > Private Sub BtnExit_Click()
    > > End Sub
    > >

    >
    >




  4. #4
    Matt
    Guest

    Re: Need some help with Exit Event

    Good point Bob- Any idea of code that would allow the data to be saved
    as well.

    I'm also looking for a pop-up box which upon pressing the exit button
    would ask the user if they wanted to save the form w/ data -- if yes
    would save and if no would exit the entire application.

    Thanks for everyone's help!


  5. #5
    Bob Phillips
    Guest

    Re: Need some help with Exit Event

    Matt,

    You would have to hive it off somewhere, like a hidden worksheet or a text
    file, and then the next time you open the form, re-in state it. All manual I
    am afraid.

    ans = MsgBox("Save the Form", vbYesNo)
    If ans = vbYes
    'call the save routine
    Else
    End
    End If

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Matt" <mlaipple@yahoo.com> wrote in message
    news:1112283327.883933.50200@l41g2000cwc.googlegroups.com...
    > Good point Bob- Any idea of code that would allow the data to be saved
    > as well.
    >
    > I'm also looking for a pop-up box which upon pressing the exit button
    > would ask the user if they wanted to save the form w/ data -- if yes
    > would save and if no would exit the entire application.
    >
    > Thanks for everyone's help!
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1