Track Changes VBA Granular information needed

J

Jay Freedman

Several things to investigate (I have no idea which if any of them will turn
out to be at fault):

- Do you have an End If statement to close the If .Range.Text statement? Is
it in the right place, right after the last .Cells statement of the ElseIf
sequence?

- Single-step through the macro using the F8 key. When you get to the If
..Range.Text statement, exactly what is the value of .Range.Text? Maybe it's
more than one character, in which case the If condition would be False. Be
especially aware that it could be a punctuation character followed by one or
more spaces. Try using statements like this:

If Trim(.Range.Text) = "," Then

The Trim() function removes any leading or trailing spaces from the string.

- While you're single-stepping the macro, verify that the execution does get
to the If .Range.Text statement -- maybe the oRevision.Type value isn't
wdRevisionDelete.

A minor correction: the character ":" is a colon, not a semicolon.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
K

Krumrei

This code works.

ElseIf oRevision.Type = wdRevisionDelete Then
.Cells(3).Range.Text = "deleted"
'Apply automatic color (black on white)
oRow.Range.Font.Color = wdColorAutomatic


Then when I add this, it still pulls the "deleted" text, but not in Cell(3)
with the words "deleted" It is not grabbing the text range.



ElseIf oRevision.Type = wdRevisionDelete Then
If .range.text = "," Then
..Cells(3).Range.Text = "Comma Deleted"
'Apply automatic color (black on white)
oRow.Range.Font.Color = wdColorAutomatic
End If
 
J

Jay Freedman

I have a suspicion, but I can't tell by looking at just this little bit of
the code...

When you write .Range.Text, or any expression that starts with a dot, that
assumes there is a line

With oRevision

somewhere before that (and a matching End With somewhere afterward) to
specify _which object_ you're getting the range from. I think you've left
that part out, so the .Range is referring to whatever object you _do_ have a
"With" statement for -- probably ActiveDocument. Of course, the range of
that object isn't going to be just a comma, so the If condition will always
be false.

The most effective fix will be to include the oRevision object in each If
statement, like

If oRevision.Range.Text = "," Then

so there's no ambiguity about which object is being used there.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
K

Krumrei

I so owe you a beer!


Adding that oRevision in the .Range was what the issue was!

Super, thank you so much for the 22 some odd replies!


You are great!


Paul
 
K

Krumrei

One last question.

I want to pull comments in the program too.

I added this.


Dim cmt = Comments


ElseIf ocmt.Range.Text = "0" Then
.Cells(3).Range.Text = "Comments"


Was wondering what Range, comments are under, or wd Properties?




Thanks!
 
J

Jay Freedman

Krumrei said:
One last question.

I want to pull comments in the program too.

I added this.


Dim cmt = Comments


ElseIf ocmt.Range.Text = "0" Then
.Cells(3).Range.Text = "Comments"


Was wondering what Range, comments are under, or wd Properties?

As far as VBA is concerned, comments are completely separate from tracked
changes. Just as the tracked changes are in the ActiveDocument.Revisions
collection, the comments are in the ActiveDocument.Comments collection, and
they have nothing to do with each other.

You would need a separate part of your macro devoted to handling comments,
with a separate loop

Dim oCmt As Comment

For Each oCmt In ActiveDocument.Comments
' extract the properties of oCmt here, like this...
.Cells(2).Range.Text = oCmt.Author
.Cells(3).Range.Text = oCmt.Range.Text
Next

This loop cannot be intermixed with the loop that handles the Revisions
collection -- they must be separate loops. If you want the extracted table
to put the comments in between the tracked changes in the same order they
occur in the original document, you'll have to do that separately by keeping
track of the .Range.Start and .Range.End values (which are, respectively,
the number of characters from the beginning of the document to the start and
end of the Range) and inserting or moving table rows to match.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
K

Krumrei

Thanks Jay,

I made a seperate report, it is much easier than having to mix the two, plus
for metrics purposes, I added the count method in both reports to show me how
many track changes and comments are within the document.

Thanks again for all your help!


Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top