• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

Word Macro SaveAs Issue

I have the following lines of code that shows a Word SaveAs dialog box.  The only problem is that if my Lease Writers press cancel, the macro keeps running and overwrites the Word "boiler."  This occurs even though the boiler is read only.  Is there any way that I can have as part of the SaveAs dialog box, a warning not to press "Cancel"?  Or, is there a way to capture a cancel selection and then quit running the macro?  Thank you.

    Dim dlg As Dialog
    Set dlg = Dialogs(wdDialogFileSaveAs)
    dlg.Name = strFileName
    dlg.Show
0
rvfowler2
Asked:
rvfowler2
  • 2
1 Solution
 
GrahamSkanRetiredCommented:
You can test it something like this:
    Dim dlg As Dialog
    Set dlg = Dialogs(wdDialogFileSaveAs)
    dlg.Name = strFileName
    IF dlg.Show <> -1 then
         exit sub
    end if

Open in new window

0
 
rvfowler2Author Commented:
tested it, but for some reason the IF dlg.Show line cause the SaveAs Dialog box to come up again.  Then, if I cancel a 2nd time, then it goes to the Exit Sub line and executes.  Not sure why the 2nd instance of the SaveAs dialog box.
0
 
rvfowler2Author Commented:
Sorry, my bad.  Had added your last lines to the end of mine and didn't notice you had removed the dlg.Show and replaced it with the IF statement.  I'm not used to IF statements also executing something.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now