Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 22

Thread: Range Revision Issue

  1. #1
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location

    Range Revision Issue

    I've got the following code I'm running from Access that shows everything I select in the document as "wdRevisionInsert" for the type. If I accept all changes then I can get no revision status. Any idea why I can get "wdNoRevision" on anything I select?

    
    dim AppWrd as new word.application
    dim rng as word.range
    
    set sdDoc = ActiveDocument
    Set rng = WdDoc.range
    
    with rng.find
        .text = "the"  'Anything that doesn't have revision history as show with "All Markup" selected
        .execute
    end with
    
    if rng.revisions(1).type = wdNoRevision
        stop
    end if

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Simply because there'll be no rng.revisions(1) to test... Use rng.revisions.count instead.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    Quote Originally Posted by macropod View Post
    Simply because there'll be no rng.revisions(1) to test... Use rng.revisions.count instead.
    Shows 1 or greater for everything using rng.revisions.count. "rng.revisions(1).type = wdNoRevision" works if I accept all changes.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by heedaf View Post
    Shows 1 or greater for everything using rng.revisions.count. "rng.revisions(1).type = wdNoRevision" works if I accept all changes.
    Not after you've accepted the revisions it won't.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    Correct. I just stated that to show that it wasn't stuck. The point is that it doesn't change on anything I set the range to if it has any revision history or not.

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Fairly obviously, I would have thought, it does change if you run it before and after. It might be helpul if you told us what you're trying to achieve.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    I would like to know if a specified range has revision history with it. Everything I've tried there is no change in the count.

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Sub Demo()
    With ActiveDocument.Range
      With .Find
        .Text = "string to find"
        .Execute
      End With
      MsgBox "Revisions Found: " & .Revisions.Count
    End With
    End Sub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  9. #9
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    Thank you for the reply. I've tried what you suggested and if a word that is found has revisions or doesn't have revisions the count is always 1. I would assume that if there is no revisions it would be 0, am I mistaken?

  10. #10
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    For me, if there are no revisions in the found range, it returns 0! Did you actually try it? Did you check the content of the found range, with revisions visible?
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  11. #11
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    Yes. It is really weird. I've played with it for a long time. I've got the document showing all revisions and when I pick a string that has markups it will only show 0. I can get it to work in other documents but for some reason it won't work in this document. The revision is created via a vba a script that sets the revision name and makes changes throughout the document so I can track the changes and verify they were done correctly. Could this be a problem? As far as I can tell the revision looks normal.

  12. #12
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    ​Without actually seeing the problem document, it can be difficult for anyone to diagnose the issue. Can you attach a document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.

    Please also provide details of the string you're trying to find.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  13. #13
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    Paul, thank you for the response. I failed to try rebooting the computer and it is now working. If I remember right, just shutting down Word doesn't work, I have to reboot the computer. Any idea on what the cause is?

  14. #14
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    I've got the same problem again. I'm on a different network and can't move the database/documents. I did find a curiosity thou. I have:
    rng.find.execute FindText:="[0-9]{4,}", MatchWildCards
    and
    rng.select
    to verify that it was found in the Word document. When I look at the rng.revisions.count it looks like it is showing all the revisions in the document even though the range is set to what is found. However, if I do
    Selection.range.revisions.count
    on what the find found the value is correct. Any idea on what is going on or what I have done wrong.

  15. #15
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    All that might mean is that 'rng' originally referred to the entire document and your Find term wasn't found.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  16. #16
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    So rng.select highlights the string I want. I did find what the problem might be but I don't understand why. The first .find result was located in the table of contents and the revision.count resulted in the total number of revisions in the entire document. So the rng.select showed the correct string in the table of contents but the revisions data is wrong. When .find was in the body of the document seems to work fine. Any idea why this would be the case?

  17. #17
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    So disregard my previous post since it stopped working again. Looks like the revision on a range has problems since it works intermittently. The solution that seems to work reliably for me is to use rng.select and than do selection.range.revisions.count. So if anyone runs into the same problem I hope that helps.

  18. #18
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Since post 1# shows that you start off with:
    Set rng = WdDoc.range
    a failure to find the specified text via .Find leaves rng spanning the whole document. It doesn't matter whether you define rng that way of by using .Select; the result will be the same - rng will always span whatever it initially points to if the text isn't found.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  19. #19
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    107
    Location
    rng.find finds what I'm looking for and if I do rng.select I can see it highlighted in the document. Most options work just find for rng.text, rng.font. etc. but for some reason .revision. options are hit or miss on working. So if I do .selection.range.count on what was found it works just fine.

  20. #20
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    As I've said before, it works for me. The only conclusion I can draw is that there's a problem with your implementation.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

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
  •