Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 06-16-2012, 02:34 AM
macropod's Avatar
macropod macropod is offline Extract phone number from word file Windows 7 64bit Extract phone number from word file Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,512
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

OK, try the following version of the macro. You don't even need to create the output document beforehand - the macro does that for itself.
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrTxt As String
StrTxt = ""
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "FirstN*[0-9]{3}[\+\-][0-9]{3}[\+\-][0-9]{4}*LastN\=*>?"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    If InStr(StrTxt, .Duplicate.Text) = 0 Then StrTxt = StrTxt & .Duplicate.Text & "|"
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Documents.Add
With ActiveDocument.Range
  .InsertAfter Replace(StrTxt, "|", vbCr)
  .Characters.Last.Delete
End With
Application.ScreenUpdating = True
End Sub
PS: The phone# format in your latest post differs from what you originally posted. The revised code will handle either format.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract phone number from word file Extract Video from .ppsx file designer PowerPoint 1 10-14-2011 08:00 AM
Extract phone number from word file Phone number formatting Mark Micallef Outlook 1 08-04-2010 02:38 PM
Can I Extract a Page from Word and Make a New DOCX File? tatihulot Word 1 06-20-2010 11:38 PM
in WORD, how do i type a 9-digit phone number "xxxxxxxxx" and have it automatically.. jay8962 Word 0 04-08-2010 11:08 AM
automatically extract footnotes into new file and apply character format to footnote hrdwa Word 0 02-27-2010 03:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft