Results 1 to 3 of 3

Thread: Prompt user if file save is cancelled
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular sharky12345's Avatar
    Join Date
    Aug 2010
    Posts
    3,235
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Prompt user if file save is cancelled

    I have a routine which prompts the user to choose a folder to save an embedded Word document as PDF;

    Code:
    FilePath = Application.GetSaveAsFilename(InitialFileName:=File121, FileFilter:="PDF Files (*.pdf), *.pdf", Title:="Select Folder to save")
    It works fine, except if the user clicks cancel in which case it doesn't save the file but carries on with the rest of the procedure, which is not what I want so I need to incorporate a method to do the following if they click cancel;

    1) Prompt asking if they want to cancel - if yes then exit sub
    2) If they choose to try again then show the GetSaveAsFilename dialog again (then repeat the process)

    What I'm trying to do essentially is come up with a way that they either keep going back to choose a folder to save or exit the routine.

    Hope I've made sense!
    There isn't a day go by without me learning something new about VBA!

  2. #2
    Board Regular
    Join Date
    Jul 2012
    Location
    Hampshire, UK
    Posts
    5,038
    Post Thanks / Like
    Mentioned
    26 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Prompt user if file save is cancelled

    Hi,
    try following & see if does what you want

    Code:
    Dim FilePath As Variant
    
    
    Do
        FilePath = Application.GetSaveAsFilename(InitialFileName:=File121, FileFilter:="PDF Files (*.pdf), *.pdf", Title:="Select Folder to save")
        If FilePath = False Then If MsgBox("Do You Want To Cancel?", 36, "Cancel") = vbYes Then Exit Sub
    Loop Until VarType(FilePath) <> vbBoolean
    
    
    'rest of code
    Dave
    Last edited by dmt32; Sep 15th, 2019 at 03:51 AM.

  3. #3
    MrExcel MVP mikerickson's Avatar
    Join Date
    Jan 2007
    Location
    Davis CA
    Posts
    22,584
    Post Thanks / Like
    Mentioned
    20 Post(s)
    Tagged
    15 Thread(s)

    Default Re: Prompt user if file save is cancelled

    This should work

    Code:
    strFilePath = vbNullString
    
    Do While strFilePath = vbNullString
        strFilePath = Application.GetSaveAsFilename(InitialFileName:=File121, FileFilter:="PDF Files (*.pdf), *.pdf", Title:="Select Folder to save")
    
        If strFilePath = "False" Then
            If MsgBox("Cancel operation", vbRetryCancel + vbDefaultButton2) = vbCancel Then
                Exit Sub
            Else
                strFilePath = vbNullString
            End If
        End If
    Loop
    
    '...
    Last edited by mikerickson; Sep 15th, 2019 at 04:00 AM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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