views:

48

answers:

1

I found an interesting thing:

In word 2010, select some text, and run the following VBA code:

public Sub Test()
    With Selection.Range.Find
        MsgBox .Execute(Selection.Range.text) 
        MsgBox .Found
    End With
End Sub

Both the two message box say "False", but both should be "True". Why?

Thanks a lot for your suggestion.

A: 

Very interesting!

Word 2007 exhibits the same behaviour.

The curious thing is that this not only when you are searching from VBA: If you select some text in the doc and press "find", the find dialog displays as default the selected text as objective.
By pressing "Find Next >" Word displays an error message "Word has reached the end of the document ... etc".

This doesn't happen if you modify the text to search deleting the last character. VBA is consistent with that: the folowing code works!

Sub tt()
    With Selection.Range.Find    
       MsgBox .Execute(Mid(Selection.Range.Text,1,Len(Selection.Range.Text)-1))  
       MsgBox .Found  
    End With  
End Sub

Not solved ... but proved to be consistent with the GUI.

HTH!

belisarius
Thank you very much for your response.
dxjh