Illogical Errorq

S

Sahana

I m trying to add - after word "pre"

Technically, macros should not check for pre-defined. As - is added
after pre. But macros I m trying to execute is checking for pre-
defined also.

Can someone tell me where I m going wrong?

Code is

Sub PRELhyphen()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng
With .FInd
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute("pre-[A-Za-z]{1,}>", MatchWildcards:=True)
oRng.Select
Select Case Msgbox(Chr(34) & "pre" & Chr(34) & " on page " &
Selection.Information(wdActiveEndPageNumber) & " should be followed by
a hyphen. Please refer to the dictionary for clarification.",
vbYesNoCancel, "Pre")
Case vbCancel
Exit Sub
Case vbYes
oRng = Replace(oRng.Text, "pre-", "pre")
End Select
oRng.Collapse wdCollapseEnd
Loop
End With
End With
End Sub
 
D

Doug Robbins - Word MVP

As a minimum,

Do While .Execute("pre-[A-Za-z]{1,}>", MatchWildcards:=True)

should be

Do While .Execute(FindText:="pre-[A-Za-z]{1,}>", MatchWildcards:=True) =
True

and more likely, it should be

Do While .Execute(FindText:="pre[A-Za-z]{1,}>", MatchWildcards:=True) = True

if you do not want it to find pre-defined.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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