Macros and track changes

A

Amy

Hi, I have created some macros that do various "find/replace" actions. But I
notice that the macros do not work when "track changes" is turned on. Is
there a way to run these kinds of macros with track changes turned on?

Thanks
Amy
 
D

Dave Lett

Hi Amy,

It seems to work fine in my environment (Windows XP and Word 2003)

ActiveDocument.TrackRevisions = True
With Selection.Find
.Text = "test"
With .Replacement
.Text = "Replaced"
End With
.Execute Replace:=wdReplaceAll
End With

HTH,
Dave
 
J

Jay Freedman

The idea is to find out whether Tracking is on, and save that result in a
variable. Then turn off Tracking, do your work, and finally restore the
original state. Here's code:

Dim WasTrackingOn As Boolean
WasTrackingOn = ActiveDocument.TrackRevisions
ActiveDocument.TrackRevisions = False

' do your find/replace operations here

ActiveDocument.TrackRevisions = WasTrackingOn

Of course, if you use a variable of Document type to work on some other
document, substitute that variable for ActiveDocument.

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

Helmut Weber

Hi Amy,

not really, IMHO.
Unless you *must* track changes,
make sure, track track changes is turned of.
Otherwise, you'd have to check whether
the range of the found text has a revisions count > 0.

Still there is the danger of endless loops.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Jonathan West

Amy said:
Hi, I have created some macros that do various "find/replace" actions. But
I
notice that the macros do not work when "track changes" is turned on. Is
there a way to run these kinds of macros with track changes turned on?

Thanks
Amy

The problem is probably that the macros are working, but the conditions are
not as you would expect them to be,

Suppose you originally had "this whole phrase" in the document, and then
decided to delete "whole". So you now have "this phrase", and you do a
search on that string. The Find will *not* find it, because "whole" is still
there but marked with a deletion.

Furthermore, if deleted text is hidden, the Find won't find "this whole
phrase" either, but it will find it if the deleted text is marked with
strikethrough or some other visible formatting.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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