|
-
Nov 23rd, 2005, 08:01 AM
#1
Thread Starter
New Member
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.
-
Dec 2nd, 2005, 07:31 AM
#2
Re: Word macro to select certain kind of words
 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:
Sub CopySpecificWordsToNewDoc()
Application.ScreenUpdating = False
'Declare a variable for current document
Dim CurDoc As Document
'Declare a variable for new document
Dim NewDoc As Document
'Place the cursor on the top of the document
Selection.HomeKey unit:=wdStory
'Assign the active document to variable CurDoc
Set CurDoc = ActiveDocument
'Add new Word Document
Documents.Add
'Assign the new document to variable NewDoc
Set NewDoc = ActiveDocument
'Activate the Old Document
CurDoc.Activate
'Find the 6 letter word starts with "K"
With Selection.Find
Do While .Execute(FindText:="<K?????", MatchWildcards:=True) = True
If .Found Then
'if found add it to the new doc
NewDoc.Range.InsertAfter Selection.Text & Chr(13)
End If
Loop
End With
'Activates the new document
NewDoc.Activate
Application.ScreenUpdating = True
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|