Reputation: 5261
I want to save a Word document according to this condition:
IF 'check something' Then:
Dim myDialog As Object
Set myDialog = Dialogs(wdDialogFileSaveAs)
myDialog.Display
myDialog.Execute
End if
Continue doing all the rest...
If the Save As window opens and the user closes it without saving by clicking the (X) on the upper corner the sub continues to run as if the user decides to save the file.
How can I exit the sub if the user closes the Save As window?
Upvotes: 0
Views: 422
Reputation: 5471
Try this. I have used Excel VBA, but you can easily change it for Word.
Sub Test()
myDialog = False
myDialog = Application.Dialogs(xlDialogSaveAs).Show
If myDialog = False Then
MsgBox "Don't Execute"
Exit Sub
Else
MsgBox "Execute Stuff"
End If
MsgBox "After If Condition"
End Sub
Upvotes: 1