+ Reply to Thread
Results 1 to 2 of 2

Cancel Macro is user selects 'cancel' at save menu

  1. #1
    Mark
    Guest

    Cancel Macro is user selects 'cancel' at save menu

    I currently have a macro that, before it runs, the save as menu automatically
    comes up and asks the user to save his/her current data. However, I do not
    know how to code anything to cancel the process.

    Currently, if the user saves or not, the macro automatically continues. I
    want the user to be able to choose between saving or not... but then be
    prompted to continue running the macro or opt out.

    My code, as it stands, is as follows....


    Sub BackUp_Save()

    Dim SaveName As Variant
    Dim fFilter As String
    Dim NewName As String

    MsgBox "You are about to delete all data within the model. Saving is
    suggested."
    NewName = "Model BackUp"
    fFilter = "Excel Files (*.xls), *.xls"
    SaveName = Application.GetSaveAsFilename _
    (NewName, fileFilter:=fFilter)

    If SaveName = False Then
    'use cancelled--what to do?
    Else
    ThisWorkbook.SaveAs Filename:=SaveName, FileFormat:=xlWorkbookNormal
    End If

    MsgBox "The model will now perform a refresh. Please wait."

    End Sub


  2. #2
    Randall
    Guest

    Re: Cancel Macro is user selects 'cancel' at save menu

    Try a yes/no msgbox if the user wants to save or not.

    do you want to save

    if true then
    save
    else
    end 'end sub


    MsgBox Function Example
    This example uses the MsgBox function to display a critical-error
    message in a dialog box with Yes and No buttons. The No button is
    specified as the default response. The value returned by the MsgBox
    function depends on the button chosen by the user. This example assumes
    that DEMO.HLP is a Help file that contains a topic with a Help context
    number equal to 1000.

    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Msg = "Do you want to continue ?" ' Define message.
    Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
    Title = "MsgBox Demonstration" ' Define title.
    Help = "DEMO.HLP" ' Define Help file.
    Ctxt = 1000 ' Define topic
    ' context.
    ' Display message.
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then ' User chose Yes.
    MyString = "Yes" ' Perform some action.
    Else ' User chose No.
    MyString = "No" ' Perform some action.
    End If


+ 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