Results 1 to 2 of 2

Thread: Word macro to select certain kind of words

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    1

    Word macro to select certain kind of words

    My aim is the following:
    I have a large Word file with a lot of different kind of information on it. What I need there is to select all words that begin with the letter K and are 6 characters long (the other five characters can be anything). Those words should be copied and pasted onto a list of its own. It can be a Word workbook or Notepad, doesn't matter. Each of these words should be in its own row.

    Can this be done with the help of a macro, and how?
    Thanks for your help.

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Word macro to select certain kind of words

    Quote Originally Posted by riikka
    My aim is the following:
    I have a large Word file with a lot of different kind of information on it. What I need there is to select all words that begin with the letter K and are 6 characters long (the other five characters can be anything). Those words should be copied and pasted onto a list of its own. It can be a Word workbook or Notepad, doesn't matter. Each of these words should be in its own row.

    Can this be done with the help of a macro, and how?
    Thanks for your help.
    I think the following code will help you:
    VB Code:
    1. Sub CopySpecificWordsToNewDoc()
    2.     Application.ScreenUpdating = False
    3.  
    4.     'Declare a variable for current document
    5.     Dim CurDoc As Document
    6.     'Declare a variable for new document
    7.     Dim NewDoc As Document
    8.  
    9.     'Place the cursor on the top of the document
    10.     Selection.HomeKey unit:=wdStory
    11.  
    12.     'Assign the active document to variable CurDoc
    13.     Set CurDoc = ActiveDocument
    14.  
    15.     'Add new Word Document
    16.     Documents.Add
    17.  
    18.     'Assign the new document to variable NewDoc
    19.     Set NewDoc = ActiveDocument
    20.  
    21.     'Activate the Old Document
    22.     CurDoc.Activate
    23.  
    24.     'Find the 6 letter word starts with "K"
    25.     With Selection.Find
    26.         Do While .Execute(FindText:="<K?????", MatchWildcards:=True) = True
    27.             If .Found Then
    28.                 'if found add it to the new doc
    29.                 NewDoc.Range.InsertAfter Selection.Text & Chr(13)
    30.             End If
    31.         Loop
    32.     End With
    33.  
    34.     'Activates the new document
    35.     NewDoc.Activate
    36.  
    37.     Application.ScreenUpdating = True
    38. End Sub
    ___________
    CS.
    Last edited by cssriraman; Dec 2nd, 2005 at 07:34 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width