Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Delete all text except 7 digit numbers
Hi,
I receive emails that contain item numbers. All item number are 7 digits long. Examples: 2734571 #2734845 MLS#2745931 Often the numbers are found within a paragraph/sentence like... "I want more information about MLS#2745931, #2734845 and 2734571. Could you tell me more about these things." What I want to create is some sort of ... macro? Find & Replace operation? that could extract all the 7 digit numbers from text and simply list them on a seperate line after being extracted. Using the quoted text above... I want to end up with a document that just has the following text remaining... 2745931 2734845 2734571 Can someone tell me how this can be achieved? Thanks. |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Delete all text except 7 digit numbers
Something like
Sub CopyNumbersToNewDoc() Dim Source As Document Dim Target As Document Dim myRange As Range Dim sView As String Set Source = ActiveDocument sView = ActiveWindow.View.ShowFieldCodes Set Target = Documents.Add Application.ScreenUpdating = False Source.Activate Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Text = "" Do While .Execute(findText:="[0-9]{7}", _ MatchWildcards:=True, Wrap:=wdFindStop, _ Forward:=True) = True Set myRange = Selection.Range Target.Range.InsertAfter myRange & vbCr Loop End With Selection.HomeKey Unit:=wdStory ActiveWindow.View.ShowFieldCodes = sView Source.Close SaveChanges:=wdDoNotSaveChanges Target.Activate End Sub should do the trick. http://www.gmayor.com/installing_macro.htm -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org JVroom wrote: Hi, I receive emails that contain item numbers. All item number are 7 digits long. Examples: 2734571 #2734845 MLS#2745931 Often the numbers are found within a paragraph/sentence like... "I want more information about MLS#2745931, #2734845 and 2734571. Could you tell me more about these things." What I want to create is some sort of ... macro? Find & Replace operation? that could extract all the 7 digit numbers from text and simply list them on a seperate line after being extracted. Using the quoted text above... I want to end up with a document that just has the following text remaining... 2745931 2734845 2734571 Can someone tell me how this can be achieved? Thanks. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel and 15+ digit numbers | Mailmerge | |||
lost 25 digit code but have 20 digit cert of auth code | Microsoft Word Help | |||
Two decimal digit not printing correctly when last digit is a zero | Mailmerge | |||
How to replace 'any digit' with the same text? | Microsoft Word Help | |||
Formating Mail Merge of 10 digit numbers to have parenthasis+dash | Mailmerge |