• Broken Revision object in Word VBA

    Author
    Topic
    #486604

    In some Word documents I get what look to be broken objects, that is, objects that are not null or nothing but whose members display as “Object has been deleted.” Has anyone else come across these and if so, how can you fix, ovoid or test for them?
    For example, in a the code, myRevision is broken although gWordDocument.Revisions(1) is fine.

    Code:
            Dim myRevision As Revision
            For Each myRevision In gWordDocument.Revisions ‘Assume gWordDocument  is valid and gWordDocument.Revisions.count > 0
                If myRevision Is Nothing Then
                   ShowObjectError ‘Error notice is never invoked
                End If
                 Debug.Print myRevision.Author ‘Produces an error: Err = -2147467259/Description: Automation error Unspecified error
     
            Next
    

    The attached graphic shows the debug informaiton for the myRevision object and the corresponding Item object in the Revisions tree.

    Viewing 3 reply threads
    Author
    Replies
    • #1360204

      ForEachLoop,

      Check me here, but aren’t collections Zero based not One based? If so, then the first time through the loop you would be looking at (0) not (1).
      Now why the “Is Nothing” is not working has me stumped also, unless the instance is there but all the properties have been deleted. :confused:
      :cheers:

      May the Forces of good computing be with you!

      RG

      PowerShell & VBA Rule!
      Computer Specs

    • #1360206

      I’ve found that with revisions, a For Each … Next loop doesn’t always work. Try:

      Code:
      Dim i As Long
      With ActiveDocument
        For i = 1 To .Revisions.Count
          MsgBox .Revisions(i).Author
        Next
      End With

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #1360338

        Thanks! I like getting confirmation that the problem is actually an exception to the rule. Which segues to the next question. For Each Next is slow enough as it is, a For Next is even slower. In documents with a sufficiently large number of revisions, this process takes forever. Is there a way to get that Revision information into a memory structure, something like Revision.ToList() kind of thing?

    • #1360402

      Given that you’re working with a collection, I doubt there’s much you can do. A dictionary object might be faster to process, but you’d still have the overhead of populating it.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

    • #1360959

      I got around a little of this by reading the 2003 version’s RTF and 2007’s XML to get a list of revision authors. For our large, marked up documents, it was taking 45+ minutes to use conventional For loops just reading the Revisions to compile an author’s list; now it’s trivial, perhaps as long as 10 seconds. I still have the overhead of reading the revisions.

    Viewing 3 reply threads
    Reply To: Broken Revision object in Word VBA

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: