Macro to search words using word 2000

C

constance

Hi everybody,
I'm trying to write a function which searches a expression and not
word
I have this macro who search the word "formation"

Sub searchFormation()

Dim intCount As Integer
Dim strSearch As String
Dim str As String
'Permet de n'activer la macro qu'une fois sur un même document

strSearch = "formation"

For intCount = 1 To ActiveDocument.Words.Count
With ActiveDocument
str = LCase(Trim(ActiveDocument.Words(intCount)))
If (LCase(Trim(ActiveDocument.Words(intCount))) = strSearch) Then
Response = MsgBox("Word found.", vbOKOnly, "Error")
End If
End With
Next

End Sub


I want a macro which searches an expression of words like "formatio
:".

can somebody help me ?

Thanks

Lyn
 
D

Doug Robbins - Word MVP

Hi Lynn,

Word's Edit>Find can be used to search of an expression in addition to
single words. Here's a macro that can be used:

' Macro created 27-10-98 by Doug Robbins to get the number of times that a
word appears
'
Dim Message, Title, Default, MyValue
Message = "Enter the word for which you need the number of occurences" '
Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)
Selection.HomeKey Unit:=wdStory
With ActiveDocument.Content.Find
.ClearFormatting
Counter = 0
Do While .Execute(FindText:=MyValue, Forward:=True) = True
Counter = Counter + 1
Loop
End With
MsgBox "The word " + MyValue + " appears" + Str$(Counter) + " times."

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
*If you're seeing this through Irubin's crappy web site, you should know
that he does not have my permission to include this message on his website.
I own the copyright, and I grant a license to Microsoft, Google and the
usenet community. I deny Irubin the right to repost my message on his site.*
 

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