Prompt user if file save is cancelled

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
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!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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:
Upvote 0
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:
Upvote 0

Forum statistics

Threads
1,213,495
Messages
6,113,992
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top