Problem with find and replace using wdReplaceAll

K

keith

Hello,

I am using VBA to edit documents with a complex page and
line numbering system. The VBA is very effective, but
I've encountered a problem with a large document. Here is
the situation.

The source document comes from a mainframe system. Each
line of the source document text begins with an indicator
of page and line. For example.

15 3 text text text
15 4 more text more text

I can remove the numbers using a for/next loop that
identifies each possible combination of page and line
number and then changes the combination to some other
value. With the assistance of the macro builder plus
my enhancements, I created the following code.

For I = 1 to MaxPages

' code here creates string1
' in much the same way that
' String2 is created below

For j = 1 To MaxLinesPerPage

If j < 10 Then
String2 = Format(Str(j), " 0")
Else
String2 = Format(Str(j), " 00")
End If

String0 = String1 & String2

myrange.Find.Execute FindText:=String0, _
ReplaceWith:=String3, _
Replace:=wdReplaceAll

And so on.

The code works great. However, with a large document
there can be over 1,000 lines and over 1,000 calls to this
findtext method. With that many calls, the Word "can't
undo" warning pops up. In a test document I've had to
click the "can't undo" dialog box over 100 times before it
goes away. I also receive a warning that there have been
too many edits on the document. Searching help, I do not
fnd a way to either turn-off off or respond to either
warning.

How can I either turn off or programmatically answer "ok"
to all those "can't undo" and "too many edits" warnings?

Thank you

Keith
 
S

Steve Lang

Hi Keith,

Try using the Application.DisplayAlerts property. You can set it to none, so
no alerts are displayed. Remember to reinstate it to all when your code is
done, since the scope of the setting is for the application, not just your
code.

HTH and have a great day!

Steve
 
K

keith

Hi Steve,
Thanks very much,
keith
-----Original Message-----
Hi Keith,

Try using the Application.DisplayAlerts property. You can set it to none, so
no alerts are displayed. Remember to reinstate it to all when your code is
done, since the scope of the setting is for the application, not just your
code.

HTH and have a great day!

Steve



.
 
P

Peter Hewett

Hi keith

You may also want to change:
myrange.Find.Execute FindText:=String0, _

to:
ActiveDocument.UndoClear
myrange.Find.Execute FindText:=String0, _

this will flush the undo buffer.

HTH + Cheers - Peter
 

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