locked
How to reference document's window when file is open in Compatibility Mode. RRS feed

  • Question

  • I have a macro which runs on Document_Open.  It does a mail merge, then closes the original template document.

    Dim DocName$
        DocName = ActiveDocument.Name
         'Do mailmerge

    ...........
             'Close mailmerge document
        ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
        Windows(DocName).Close wdDoNotSaveChanges

    I'm getting "Item not found in collection" on the last line. The Close statement.  The problem is that my file is being opened in Compatibility Mode and DocName is "GiftCardReceipt[1].doc".  But it can't find the document to close it.  I think the reason is that the window title for the document is actually "GiftCardReceipt[1].doc  Compatibility Mode". 

    How can fix this so it closes the document?

    Thanks,

    Dave

    Thursday, October 13, 2011 2:26 PM

Answers