Results 1 to 6 of 6
  1. #1
    Lounger
    Join Date
    Mar 2010
    Location
    Texas
    Posts
    49
    Thanks
    4
    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. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    5,965
    Thanks
    193
    Thanked 730 Times in 666 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


  4. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,823
    Thanks
    0
    Thanked 168 Times in 155 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]

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

    ForEachLoop (2012-11-30)

  6. #4
    Lounger
    Join Date
    Mar 2010
    Location
    Texas
    Posts
    49
    Thanks
    4
    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?

  7. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,823
    Thanks
    0
    Thanked 168 Times in 155 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]

  8. #6
    Lounger
    Join Date
    Mar 2010
    Location
    Texas
    Posts
    49
    Thanks
    4
    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
  •