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
LVL 2
rvfowler2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.