Closing a Word document without saving

  • MODERATOR NOTICE: This topic has also been posted on other sites and may already have an answer elsewhere. Please take this into consideration when answering this question

    Hi there

    I'm looking for some help on a code query.

    I've pulled some code together to run a mail merge. I initially ran the code via my office 365 Excel application and all worked fine. However, I needed to run the code on Office 2016 and there is one line of code that isn't functioning.

    It's the line of code wdocSource.Close SaveChanges:=wdDoNotSaveChanges that did not function. The code stops running awaiting a manual input to the save/don't save dialogue box before the code then completes its run. It seems to ignore the code that is supposed to close the word document down without saving.

    Any help would be appreciated.

  • Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post. We are here to help so help us help you!

    Read this to understand why we ask you to do this

    Try this

    1. wdApp.ActiveDocument.Close SaveChanges:=wdSaveChanges
  • Hi there. Thanks for responding. Regarding the moderator notice it was me that posted this question on another forum but didn't get a solution.

    Also I didn't realise is posted in someone else's thread as thought I'd started this as a new thread! Apologies if I have broken forum rules/etiquette :-/

    I feel like the issue is in some way connected to the Excel version and a possible missing attribute but clearly have nothing to validate this. I just can't rationalise why the macro simply ignores this one line of code and stalls pending manual intervention.

    Thanks again for taking time to respond.

  • Totally makes sense. Thanks for explaining. Yes I tried your code but for some reason the macro is still ignoring this line of code and manually prompting to save (or not) the document. I'm wondering if there's an option to change the code to save as the document with the same doc title and overwrite the existing. I'll try this out and see if this works. Cheers

  • Actually scrap that idea. I've managed to make it work. I moved the offending line of code to later in the macro and now works!! Bizarre.

    Thanks again for all your help. How do I mark as solved?

  • I don't code much Word VBA but maybe you just need to save the document first

    1. wdApp.ActiveDocument.SaveAs "C:\Users\macde\Desktop\Merge test\final_letter.docx"
    2. wdApp.Save
    3. wdApp.ActiveDocument.Close


    1. With wdApp.ActiveDocument
    2. .SaveAs Filename:=("somePath" & "aName"), FileFormat:=wdFormatDocumentDefault
    3. .Close
    4. End With