PDA

View Full Version : once again a question about wdRevisionDelete



marcelma
11-15-2010, 02:47 PM
Hello,

I am still looking for a good method to find out whether a certain character is marked as deleted/inserted or not. If several revisions have been made, a question like :

If Selection.Range.Revisions(1).Type = wdRevisionDelete Then
will not get me very far. Is there any shorter way of finding out than running through a loop which checks all Revisions from 1 to

Selection.Range.Revisions.Count ?
I would be thrilled about a suggestion which takes up less time than a loop.

Marcel

fumei
11-15-2010, 03:19 PM
You need to clarify things.

Say you have the word:

here

and you change ONLY the "h" to "d"

dere

You get Deleted: here

The whole word is marked.

Now suppose you change the "d" to "b", so the word has gone from: here to dere to bere.

A single character changed twice.

The Revisions will still be" Deleted: here

So what do you mean by "several revisions". Do you mean several revisions of the SAME character? Several revisions at all?

BTW: the .Count of the revisions (from "h' to "d" to "b") = 1

Yes, you can get Revision(index).Range.Text.

Revision(1).Range.Text would return the CURRENT text.

Now if you change the word this is another thing entirely. But you seem to have focus on characters.

marcelma
11-15-2010, 03:55 PM
Hello Gerry,

As it happens often, I thought I'm clear, but I can see now that I wasn't :-)

Take a word like "here", which is inside a paragraph. Now, let's assume somebody has changed the paragraph style. Then let's assume sombody has formated the word "here" with some character style. At last somebody has deleted the "h" and inserted a "b" instead. If I have highlighted the "h" of the word "here" and inquire:
Selection.Range.Revisions(1).Type I will get 10 as a result (wdRevisionParagraphProperty) if I enquire further about:
Selection.Range.Revisions(2).Type I will get 3 as a result (wdRevisionProperty). If finally I enquire about:
Selection.Range.Revisions(3).Type I will get 2 as a result (wdRevisionDelete).

Since I do not know from the beginning by how many revisions the highlighted character has been affected, it seems I need to run a loop like:

Dim V_Loop = Integer
Dim Vb_RevDeleted = Boolean
For V_Loop = 1 To Selection.Range.Revisions.Count
If Selection.Range.Revisions(V_Loop).Type) = wdRevisionDelete Then
Vb_RevDeleted = True
End If
Next V_Loop

So, what I am looking for is a method of finding out whether a certain selection contains a deleted character or not without having to ask about all the other possible revisions at this place.

greetings,
Marcel

fumei
11-15-2010, 04:38 PM
"Take a word like "here", which is inside a paragraph. " This is not saying much. All text is inside a paragraph. It is not possible to have text NOT inside a paragraph.

Dim V_Loop = Integer
Dim Vb_RevDeleted = Boolean
I get an error is I use equal signs. Don't you mean As?


Selection.Range.Revisions(V_Loop).Type)has too many brackets.

In any case, I have duplicated EXACTLY the situation you describe.

I have a style - Gerry. I apply it to a paragraph with "here".

I then change the paragraph style (to TheOther)

I then change "here" to a Character style (MyChar)

I select the "h"

BTW: I assume since you state select the "h" that you are viewing Original - rather than Final With Markup. Otherwise you would not be able to SEE the "h".

Let's say the whole paragraph is:

Yadda blah here.

(now Yadda blah bere).

You may find it instructive to run the following procedure.
Sub YaddaBlah()
Dim j As Long
For j = 1 To Selection.Range.Revisions.Count
MsgBox Selection.Range.Revisions(j).Range.Text & _
vbCrLf & Selection.Range.Revisions(j).Type & _
vbCrLf & Selection.Range.Revisions(j).Index
Next
End Sub
It iterates - as your code does - through the revisions. Remember only the "h"' is selected!

The first message:

Yadda blah here
10
2

Note that Selection.Range.Revisions(1).Range.Text is the whole paragraph, as that is what WAS selected. If you changed the style by playing the selection and choosing the new style, it will change the style but the revision Type = 7 (Conflict).

Anyway...........

"So, what I am looking for is a method of finding out whether a certain selection contains a deleted character or not without having to ask about all the other possible revisions at this place."

You code is clunky. You can check through all the revision much easier. Again, it is always much better to use objects. You want to check revisions, USE revisions
Dim myRev As Revision
Dim Yup As Boolean
For Each myRev In Selection.Range.Revisions
If myRev.Type = wdRevisionDelete Then
Yup = True ' if you really want a boolean variable
MsgBox "Yes, this character was deleted."
Exit Sub
End If
Next



BTW: VBA no longer uses Integers. You should declare your V_Loop as Long.

fumei
11-15-2010, 04:45 PM
Or, if you are using this a lot in other code, do it as a Function.
Function WasDeleted() As Boolean
Dim myRev As Revision
For Each myRev In Selection.Range.Revisions
If myRev.Type = wdRevisionDelete Then
WasDeleted = True
Exit Function
End If
Next
End Function

Sub TryMe()
If WasDeleted Then MsgBox "Yes, it was deleted."
End Sub
Now you can select any character and fire TryMe (through a icon, a keyboard shortcut, or whatever. if the character selcted had been deleted, you get the messagebox. Adjust for your own purposes.

marcelma
11-15-2010, 05:59 PM
Hello Gerry, your 2nd post seems to pretty much what I was looking for. Thanks a lot. I'll have a closer look at both your posts tomorrow (it has become too late here, my brain is in snail mode).

greetings,
Marcel

marcelma
11-16-2010, 02:33 AM
Hello Gerry,

Your suggestion to use a function is great. It runs sooooo much quicker than the procedure I had been using before. Thank you very much.

I have modified your function a little so that it would tell me whether a selected character is deleted or inserted. Presently it looks like this:

Function F_RevType() As Long
Dim Rev As Revision
For Each Rev In Selection.Range.Revisions
If Rev.Type = wdRevisionDelete Then
F_RevType = wdRevisionDelete
Exit Function
ElseIf Rev.Type = wdRevisionInsert Then
F_RevType = wdRevisionInsert
Exit Function
Else
F_RevType = wdNoRevision
End If
Next
End Function

The function is actually not fool-proof, because it pre-supposes that the selected character is either only deleted or only inserted or has not been changed at all. It does not check for an instance in which one reviewer would have inserted the character and another reviewer would have deleted it again.

As it is now, the function works well on isolated characters which are deleted or inserted, but if there is a string of characters, it works only on the first one. For example, if I have inserted the word "hello" and mark the "h", the function would return the value 1 (wdRevisionInsert), but if I mark the "e", the function would return the value 0 (wdNoRevision).
I suppose this has something to do with the fact that the whole word "hello" is only one revision, but I need something that tells me reliably whether (supposed the text has been reviewed only by one reviewer) a certain character is inserted or deleted, no matter whether it is the 1st character in a revision or a following character.

greetings,
Marcel

marcelma
11-16-2010, 03:06 AM
Hello Gerry, I am now working through your longer post and find a lot of interesting hints in there.

First of all, sorry for having sent such a sloppy code, I had put it together by copying bits and pieces from my actual code into the message window here without actually testing it before. Your remarks about it were much to the point.


BTW: I assume since you state select the "h" that you are viewing Original - rather than Final With Markup. Otherwise you would not be able to SEE the "h".
Actually I am neither viewing Original nor Final With Markup, I can see both, the deleted and the inserted characters (WinWord 2002).

Your YaddaBlah() procedure was indeed very instructive, however, it raises a few new questions.

- under what circumstances a revision is marked as wdRevisionConflict (or wdRevisionReconcile for that matter)

- what is the meaning of the information obtained by the line Selection.Range.Revisions(j).Index ?

Actually, I am getting the impression that I am trying to write a novel in a language in which I can't yet write even a simple letter - therefore all the more thanks for your assistance.

greetings,
Marcel

fumei
11-16-2010, 12:19 PM
With Index, I wanted to see what index number it was, that is the order of revisions. It may or may not be useful information.

You need to clarify and be explicit about what you are trying to do.

In all your posts you speak about character level testing. Single character testing. So bringing in words makes things more complicated.

marcelma
11-16-2010, 01:51 PM
Hi Gerry,

I am affraid if I explain the whole project that doesn't quite fit into this thread...

Here I am trying to find out the answer to a seemlingly very straight forward question:

If a character looks red and is crossed out, I *see* that it is marked as being deleted. I just want VBA to "see" a deleted character just as unambiguously as I can see it.

But to be a bit more specific.
My main procedure contains a loop which moves through a file one character at a time. It does a certain amount of testing on each character and more in-depth testing on a selected group of characters. In the main procedure loop my only concern is that deleted characters be skipped and not tested any furter. In sub-Procedures deleted characters gain additional meaning, for example if they are adjacent to the character which is being tested by the sub-Procedure.

In any case, if I try to boil down my question in this thread to a single sentence it would be:
How can I reliably find out via VBA in the shortest possible time whether a certain character is marked as deleted.

greetings,
Marcel

fumei
11-16-2010, 02:40 PM
The shortest time? Using that Function. It goes through the revisions for that character and returns a True if there is a deletion, and then stops.

So if there are 17 revisions for that character, and the second one is a deletion, the function returns a True, and stops. The third and on revisions are not tested.

I do not think you can get any faster. You must test the revisions, and so that is what you do.

marcelma
11-16-2010, 03:10 PM
Hi Gerry,

I agree, the function you sent (which is testing the revisions) is 15 times faster than what I had been coming up with before, so I like it a lot. However, as I have been posting before I have still a problem with it. Allow me to state it again. I am using a modified version of your function:

Function F_RevType() As Long
Dim Rev As Revision
For Each Rev In Selection.Range.Revisions
If Rev.Type = wdRevisionDelete Then
F_RevType = wdRevisionDelete
Exit Function
ElseIf Rev.Type = wdRevisionInsert Then
F_RevType = wdRevisionInsert
Exit Function
Else
F_RevType = wdNoRevision
End If
Next
End Function

Now, if I have inserted the word "hello" and mark the "h", the function will correctly return the value 1 (wdRevisionInsert), but if I mark the "e", the function will return the value 0 (wdNoRevision), although the "e" has been inserted too.

Any idea what is going on there?

greetings,
Marcel

fumei
11-17-2010, 11:18 AM
It is picking up the word. And it is worse than you realize.

If you inserted "hello" fresh, then "hello" is the insert.

Now suppose you add: a paragraph mark and the text "blah blah".

Is this a NEW inserted revision? NO, it is not. This is added to the first revision. If you selected the "b" - or ANY other character - then the function returns 0, wdNoRevision.

marcelma
11-17-2010, 05:44 PM
So, it seems I won't get beyond the point at which I'm now. The code I am presently using is:


Sub Test()
Set R_ChrEnv = Selection.Range
R_ChrEnv.MoveStart wdCharacter, -12
R_ChrEnv.MoveEnd wdCharacter, 12

If F_RevType4(12, R_ChrEnv) = wdRevisionDelete Then
Stop
'The character left of the selected character has been deleted
End If
End Sub
Function F_RevType4(V_Pos, R_ChrEnv) As Long
V_RevisionsCount = R_ChrEnv.Characters.Item(V_Pos).Revisions.Count
V_Chr = R_ChrEnv.Characters.Item(V_Pos)
For V_Loop = 1 To V_RevisionsCount
If R_ChrEnv.Characters.Item(V_Pos).Revisions(V_Loop).Type = wdRevisionDelete Then
F_RevType4 = wdRevisionDelete
ElseIf R_ChrEnv.Characters.Item(V_Pos).Revisions(V_Loop).Type = wdRevisionInsert Then
F_RevType4 = wdRevisionInsert
Else
F_RevType4 = wdNoRevision
End If
Next
End Function

fumei
11-18-2010, 12:03 PM
I have no idea what you are doing. Why 12?