Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
JVroom JVroom is offline
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel and 15+ digit numbers danhattan Mailmerge 2 June 29th 07 06:42 PM
lost 25 digit code but have 20 digit cert of auth code dan666666 Microsoft Word Help 1 June 25th 07 03:14 PM
Two decimal digit not printing correctly when last digit is a zero Catherine Mailmerge 1 January 19th 07 04:36 AM
How to replace 'any digit' with the same text? Caz Microsoft Word Help 5 September 23rd 06 02:42 PM
Formating Mail Merge of 10 digit numbers to have parenthasis+dash Omega411 Mailmerge 4 June 20th 05 08:08 AM


All times are GMT +1. The time now is 03:39 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"