Cycle through the Document Stories

F

frank

I'm trying to create a macro that will clean out the tracked changes created
by a program called DeltaView. DeltaView is similar to the native Word
compare and merge feature except it uses styles to show deleted and inserted
text.

Deleted text is styled as "DeltaView Deletion" style which has style
attributes of Red font and crossed out text. I want to remove all of the
text in the document that is styled with the DeltaView Deletion style. I can
achieve this by using the coding below, but it only removes the desired text
from the main part of the document. I need to ensure that this text is
removed from the headers/footers and textboxes/frames.

Why would we show the tracked changes using this program and then want to
remove them?...That's a longer boring story.

This is the code I use for the main document:

Set myRange = ActiveDocument.Content

With myRange.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Style = "DeltaView Deletion"
.Execute Replace:=wdReplaceAll
End With

Any help is always greatly appreciated.

Thank you.
 
F

frank

This is great. The coding is much cleaner than what I was trying to do. I
made some attempts at creating code that would remove this styled text from
the Headers/Footers.

The only problem I'm having with this new coding (which I had with my much
more clunkier version) is that it is still skipping the Headers/Footers when
you run the routine. I tried using the Step 2 and Step 3 coding examples
from the website you provided.

Here is the wierd part. When you run the routine Step by Step using the F8
key it works and removes the text from the Headers/Footers, but when you just
run the routine using the Run Sub/User Form button on the VBA toolbar, it
skips the Headers/Footers. It worked exactly like that with my lame attempt
at coding it.

I've never seen a routine work step by step then not work when you just run
it entirely. I'm using Office 2003. Do you know of any bugs like this in
this version?
 
F

frank

I did some more testing and apparently the macro completely ignores all
Footers in the document, but it does remove the desired text from the Headers
of the primary pages (All Headers that are NOT set to First Page Headers).

The text that it is ignoring is not in a text box. It's just text on a
paragraph mark located in the headers/footers styled as "DeltaView Deletion".

The macro still works step by step but when I run it whole it ignores almost
all of the headers and footers as I described above.
 
F

frank

Sorry to keep posting but I did a little more testing I put the following
code line inside the Do Loop of the routine:

Selection.TypeText (rngStory.StoryType & ", ")

I wanted to keep track of which Story Types the routine was cycling through.
I used the Step 3 option from the website you referred me to -- Public Sub
FindReplaceAnywhere().

I placed this code inside the loop right before:

Select Case rngStory.StoryType

which evaluates which Story Type number the routine is on. This was the
results:

when I ran the routine step by step the following Story Type numbers were
typed:

1, 2, 5, 9, 9, 9, 9, 9, 10, 11, 11, 12, 13, 15, 16

When I ran the routine in its entirety non-stop these were the numbers typed:

1, 2,

It's like when the routine runs entirely it just stops after Story Type 2
and ends the routine but when run step by step it cycles through 1 - 16.

Again sorry for all of the postings, but I'm just trying to figure this out
and I think any information I can give you might help narrow things down a
bit.
 
J

Jay Freedman

That's good sleuthing.

Obviously it's a timing problem, although I don't have a clue about what's
causing it. It would appear that Word is taking too long to go from the
Footnotes story (.StoryType = 2) to the TextFrame story (.StoryType = 5), so
rngStory is equal to Nothing at the end of the loop.

When a loop seems to be running too fast, it can often be cured by inserting a
call to the DoEvents function. The real purpose of DoEvents is to yield the
processor to Windows so it can take care of other things that are waiting.
People with more knowledge of Word's innards than me have said that it shouldn't
make any difference because Word is single-threaded, but my empirical
observation is that it can help -- and it certainly won't hurt.

Just before the line

Set rngStory = rngStory.NextStoryRange

insert a DoEvents statement (it doesn't take parameters or return a value).

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

Klaus Linke

Jay Freedman said:
People with more knowledge of Word's innards than me

(wouldn't include me)
have said that it shouldn't make any difference because
Word is single-threaded, but my empirical observation is
that it can help -- and it certainly won't hurt.

It may be single-threaded, but it definitely starts a lot of tasks that run
pretty independently of each other.
I'm sure you've seen the list in the Watch window under
"Application.Tasks"... Some are genuinely other programs that happen to be
running, but a lot of Word stuff appears there too.

Maybe that's why DoEvents sometimes helps?

Klaus
 

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