View Single Post
 
Old 08-13-2012, 08:01 AM
Venky62 Venky62 is offline Windows 7 64bit Office 2010 32bit
Advanced Beginner
 
Join Date: Jul 2012
Posts: 58
Venky62 is on a distinguished road
Default

Okay here is the code. I am assuming you know how to enter the code.
I have used "AN CC" as the search string - from the example you gave. A message box gives you the total number of words before this string. You can modify this code to do with it whatever you want.

Code:
Sub countwords()

    Dim intcount As Integer

    Selection.HomeKey Unit:=wdStory, Extend:=wdMove

    With Selection.Find
        .Text = "AN CC"
        .Forward = True
        .Wrap = wdFindStop
        .Execute
    End With

    Selection.HomeKey Unit:=wdStory, Extend:=wdExtend


    intcount = Selection.Words.Count

    Call MsgBox("The total number of words before AN CC are " & intcount, vbExclamation, Application.Name)

End Sub
Reply With Quote