Results 1 to 7 of 7

Thread: How to detect if document object has been deleted

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    How to detect if document object has been deleted

    I am trying to close an array of Word documents, some of which may have already been closed by the user.

    Dim arrDoofDocs As Integer
    Dim aDoc As Document

    aDocArray has the documents that were open when we started but some of which the user may have closed. The code works if the docs are all open

    As you can see I have tried On Error and If ... Nothing but to no avail. It hits the "object has been deleted error". What's the correct code?

    For i = 1 To arrNoofDocs
                Set aDoc = aDocArray(i)
                'On Error GoTo SkipClose
                'If aDoc Is Nothing Then GoTo SkipClose                      ' Check if doc is open. User might have closed it
                'aDoc.Close
                If Not aDoc Is Nothing Then aDoc.Close                       ' Check if doc is open. User might have closed it
    SkipClose:
            Next

    Thanks

    John
    Last edited by johndavidson; 05-05-2022 at 02:32 AM. Reason: clearer formatting

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •