Results 1 to 6 of 6
  1. #1
    Star Lounger
    Join Date
    Mar 2010
    Location
    Texas
    Posts
    52
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Broken Revision object in Word VBA

    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.
    Attached Images Attached Images

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    6,392
    Thanks
    208
    Thanked 831 Times in 764 Posts
    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.
    May the Forces of good computing be with you!

    RG

    VBA Rules!

    My Systems: Desktop Specs
    Laptop Specs


  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,945
    Thanks
    0
    Thanked 203 Times in 184 Posts
    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
    [MS MVP - Word]

  4. The Following User Says Thank You to macropod For This Useful Post:

    ForEachLoop (2012-11-30)

  5. #4
    Star Lounger
    Join Date
    Mar 2010
    Location
    Texas
    Posts
    52
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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?

  6. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,945
    Thanks
    0
    Thanked 203 Times in 184 Posts
    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
    [MS MVP - Word]

  7. #6
    Star Lounger
    Join Date
    Mar 2010
    Location
    Texas
    Posts
    52
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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.

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
  •