PDA

View Full Version : Range Revision Issue



heedaf
02-20-2020, 12:57 PM
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

macropod
02-20-2020, 04:28 PM
Simply because there'll be no rng.revisions(1) to test... Use rng.revisions.count instead.

heedaf
02-20-2020, 04:51 PM
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.

macropod
02-20-2020, 05:36 PM
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.

heedaf
02-20-2020, 06:05 PM
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.

macropod
02-20-2020, 06:18 PM
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.

heedaf
02-20-2020, 10:23 PM
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.

macropod
02-20-2020, 11:35 PM
Sub Demo()
With ActiveDocument.Range
With .Find
.Text = "string to find"
.Execute
End With
MsgBox "Revisions Found: " & .Revisions.Count
End With
End Sub

heedaf
02-20-2020, 11:46 PM
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?

macropod
02-20-2020, 11:56 PM
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?

heedaf
02-21-2020, 12:11 AM
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.

macropod
02-21-2020, 12:23 AM
​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.

heedaf
03-03-2020, 02:29 PM
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?

heedaf
03-04-2020, 11:05 AM
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.

macropod
03-04-2020, 07:43 PM
All that might mean is that 'rng' originally referred to the entire document and your Find term wasn't found.

heedaf
03-05-2020, 10:40 AM
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?

heedaf
03-05-2020, 12:44 PM
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.

macropod
03-05-2020, 02:09 PM
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.

heedaf
03-05-2020, 02:57 PM
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.

macropod
03-05-2020, 03:05 PM
As I've said before, it works for me. The only conclusion I can draw is that there's a problem with your implementation.

heedaf
03-05-2020, 03:28 PM
Sometimes it works for me. Are you using Office 2016? I really don't understand what I could have done wrong. But oh well, I guess it is one of life's great mysteries. Paul, thank you for all your help. You are a lifesaver on this forum.

macropod
03-05-2020, 05:31 PM
I normally use only Office 2010, though I do have Office 2016 also.