PDA

View Full Version : Solved: Doesn't Detect Tracked Changes in Headers . .



Ice-Tea-Jan
08-10-2009, 04:16 PM
Hello,

I know this has to do story ranges. I can't get this code to "look in" the headers (and probably other story ranges) to detect tracked changes.

Is there a quick way to look at the entire document (at once) for tracked changes -- or must you loop through every story range to do this?

Here is the code:

Sub Trackchanges()
'
'
Set oDoc = ActiveDocument
'
If oDoc.Revisions.Count = 0 Then
MsgBox "The document contains no tracked changes.", vbOKOnly
Else
End If
'
'
End Sub

Thank you so much,
Janet:doh:

macropod
08-11-2009, 12:29 AM
Hi Janet,

You need to test each story range, but that doesn't take much effort. Try:
Sub Trackchanges()
Dim oDoc As Document, RngStory As Range, i As Integer
'
Set oDoc = ActiveDocument
i = 0
'
For Each RngStory In oDoc.StoryRanges
i = RngStory.Revisions.Count
Next
'
If i = 0 Then
MsgBox "The document contains no tracked changes.", vbOKOnly
Else
MsgBox "The document contains " & i & " tracked changes.", vbOKOnly
End If
'
End Sub

Ice-Tea-Jan
08-12-2009, 03:20 PM
Hello macropod,

Thanks for the lightening-fast reply!

However, I tried this macro and it gives some inconsistent reults. It sometimes shows that there are "No tracked changes" when indeed there are many.

I checked that I copied your macro code properly.

I tested the macro with the macro stored in different ways.

For instance, the macro was invoked/stored from the document itself, the macro was invoked/stored from the Normal. dot, and the macro was invoked/stored as a global template.

I also checked it with documents using many stories, and documents with only a few stories.

I am using Word 2003. I can't understand the inconsistency.

Any ideas on this?

As always -- your expertise is valued and appreciated.
Janet

macropod
08-12-2009, 04:20 PM
Hi Janet,

Coding error! Change:
i = RngStory.Revisions.Count
to:
i = i + RngStory.Revisions.Count

Ice-Tea-Jan
08-13-2009, 07:40 PM
Yes!
Your fix appears to have worked! Thank you! :ty:
I pondered about the "accumulator" factor in RngStory.Revisions.Count. However, I had so many quirky problems with my Word application crashing that day that I did not know what to think. Not to mention that I’m still a newbie:bink:, and would not easily discern a fix for it.

I also like the message prompt letting the user know how many tracked changes the document contains. (Added bonus!)

As before, I have taken care to study your coding. Your expertise (and this forum) are very valued and appreciated. The solutions lend tremendous assistance (and learning) to a newbie.

I’m (again) sending along a contribution.

Although I had believed that I (myself) could not assist anyone with VB code on this forum; I surprised myself and answered one post.

Thanks Again from "Up Yonder" in USA! :hi:
Janet