Word 2003: Search and Replace Bug / Changes active document

G

Gunter Schmidt

Hello,

I found this problem while programming a macro and isolated it:

- copy this macro to any document or normal
- make a new document, place some text into it
- run the macro: It should do its job like expected
- make another new document with some text
- run the macro again: the active document now will be changed to a
previous one!!!

Private Sub Test()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "a"
.Replacement.Text = "b"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

.Execute Replace:=wdReplaceAll 'In Word 2003 the active
document will change!!! Bug.

End With

End Sub


Can you confirm this bug?

regards,
Gunter
 
J

Jay Freedman

It is not a bug; it's doing what you told it to do. The Selection
object refers to wherever the active insertion point is at the time
the macro runs, which may not be the document you're looking at.

To be certain about which document will be affected, declare a Range
object, set it to the range of a specific document, and use its Find
property instead of the Selection.Find.

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

Gunter Schmidt

Jay said:
It is not a bug; it's doing what you told it to do. The Selection
object refers to wherever the active insertion point is at the time
the macro runs, which may not be the document you're looking at.

And that is why I consider it a bug. After you write text in the second
document, the selection object should have changed. My macro worked in
all previous Versions of MW-Word (Word97, Word 2000, Word 2002).

To be certain about which document will be affected, declare a Range
object, set it to the range of a specific document, and use its Find
property instead of the Selection.Find.

That is better programming and works in 2003, too. Tx.


Gunter
 

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