Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Sep 2003
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Allow cancel during Loop of dialog box (2000/2002)

    This seems very basic, but what event do you need to test for in a dialog box (such as File Save As) if the user clicks the Close button (x) in the upper right corner of the dialog?

    I'm trying to figure out what to replace the "If FName = Cancel " with.




    ConfirmSave = MsgBox("This file is going to be saved as " + Product + FileYear + ".xls. Is that correct? "

    If ConfirmSave = vbYes Then
    On Error GoTo Resave
    ThisWorkbook.SaveAs Filename:=MyDir + "" + Product + FileYear + ".xls"

    ElseIf ConfirmSave = vbNo Then
    Resave:
    Do
    FName = Application.GetSaveAsFilename
    If FName = Cancel Then
    Exit Sub
    End If
    Loop Until FName <> False
    ThisWorkbook.SaveAs Filename:=MyDir + "" + FName + ".xls"

    Else
    Exit Sub
    End If

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Allow cancel during Loop of dialog box (2000/2002)

    If you click in GetSaveAsFilename and press F1, you'll get online help for this function. The help mentions that GetSaveAsFilename returns False if the user cancels or clicks the close button (x). So you can test

    If FName = False Then
    Exit Sub
    End If

    but that will make the Do ... Loop Until loop superfluous - you'll exit the subroutine when the user cancels, instead of looping until the user enters a name.

  3. #3
    New Lounger
    Join Date
    Sep 2003
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Allow cancel during Loop of dialog box (2000/2002)

    Thanks, Hans.

Posting Permissions

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