Error with declaration

D

Designingsally

-*Hi, I m writing macro for showing comments when certain words are
encountered.
Code is compiling well, but when I m executing the code I m encountering
with an error. The error description goes like this
Run-time error '5610'
the find what text for a find all word forms search can only contain
alphabetic letters.

When I remove - in the word "re enter". i m not encountering any error.
Clearly I have messed some declaration wrong.

can someone tell me what i must do so that macros accept words "re-enter" as
such. i have posted the code below.

thanks in advance.



Dim vFindText As Variant
Dim i As Long
vFindText = Array("Re-enter")
For i = 0 To UBound(vFindText)
With Selection
.HomeKey wdStory
With .FInd
.MatchCase = True
.MatchWholeWord = True
.ClearFormatting
Do While .Execute(findText:=vFindText(i), _
Forward:=True)
Selection.comments.Add _
Range:=Selection.Range, Text:="Kindly rephrase."
Loop
End With
End With
Next

I believe in Hope.

DesigningSally
 
P

Pesach Shelnitz

Hi Sally,

From Word's point of view, the string "re-enter" consists of two words.
Therefore, setting MatchWholeWord is not suitable for this macro. In general,
if your macros set properties of the Selection.Find object to True and any of
the checkboxes in the Find and Replace dialog box are selected as a result,
you should add code to the macro to clear those checkboxes. Take a look at
you Find and Replace dialog box and see if you have anything selected. You
should also notice that the Search for whole words checkbox is grayed out
when you search for "re-enter".
 
G

Graham Mayor

The macro you have posted works as it stands, at least in English documents
(though there is no need for the array when you have only one term to
search). What are the regional settings for your version of Windows. An
earlier post in this forum suggested that you believed re-enter was
incorrect and should be replaced by reenter. The more common form is
re-enter.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Tony Jollans

When you use "Selection.Find", Find options you have set in the UI remain in
effect unless you explicitly override them. Either make sure you explicitly
set all options or, better, use the Find object of a Range in your code
rather than the Selection.
 

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