Word 97 macro not work in Word XP

M

millahtime

I have some code that worked in Word 97 but not in Word XP. The proble
seems to be with my selection.find.execute

The code is like:

While Selection.Find.Execute
Selection.TypeText Format(BlkNo)
BlkNo = BlkNo + 1
Wend

The code here just replaces a block number. The number keep
increasing by 1 each time and it goes throught the whole document unti
it hits the end replacing the old numbers with new numbers. When it'
found the last one it stops (in word 97)

The problem is that the Selection.Find.Execute never ends in Word X
and just keeps finding the last point and adding a number to it. Thi
goes on until you end task to the program.

Is there a way to get the selection.find.execute to stop doing tha
when it has found the last point in the document? Or another easy wa
to do this
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

It would be better if you showed us the complete code because the bit that
you did show would not work by itself in Word97 either.

The following code replaces every instance of the word "fox" with a
sequential number:

Dim BlkNo As Long
BlkNo = 1
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="Fox", Wrap:=wdFindStop, Forward:=True)
= True
Selection.Range.Text = BlkNo
BlkNo = BlkNo + 1
Loop
End With

It will work in all versions of Word that use VBA - i.e Word97 and later.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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