PDA

View Full Version : [SOLVED:] Check if User pressed cancel wdDialogFileSaveAs



sparky5106
05-14-2020, 03:55 PM
Hello,

What it does: Currently I have a button on a word document that when pressed, opens the save as dialog with pre-populated filename.docm, and then opens an email in Outlook with the named document attached. If the user presses cancel instead of save, the document doesn't rename but still generates the email.

What I want it to do: If the user presses cancel I want it to exit sub so the email does not generate.

Figured out a solution


Sub SaveAs2andEmail()
With Dialogs(wdDialogFileSaveAs)
.Name = "Job Request_" & ActiveDocument.ContentControls(1).Range.Text & "_" & ActiveDocument.ContentControls(3).Range.Text
.Format = wdFormatXMLDocumentMacroEnabled
If .Show = -1 Then
GenerateEmail
Else
Exit Sub
End If
End With

End Sub