Thread: [Solved] Find what and copy that
View Single Post
 
Old 10-30-2015, 01:05 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Quote:
Originally Posted by PRA007 View Post
Step 5 is making document again at original state.
No, it doesn't, because it doesn't undo the RE insertions. If all you want after doing the data extraction is to restore the source document to its original state, why not just close it without saving?

As for the rest, try:
Code:
Sub Fees()
Application.ScreenUpdating = False
Dim StrOut As String, DocNew As Document
With ActiveDocument
  With .Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchWildcards = True
      .Text = "(US [3-9]),([0-9]{3}),([0-9]{3})"
      .Replacement.Text = "\1\2\3"
      .Execute Replace:=wdReplaceAll
      .Text = "(US )([0-9]{5} )"
      .Replacement.Text = "\1RE\2"
      .Execute Replace:=wdReplaceAll
      .Wrap = wdFindStop
      .Text = "US [R3-9][0-9E]{6}"
      .Replacement.Text = ""
      .Execute
    End With
    Do While .Find.Found
      StrOut = StrOut & Split(.Text, " ")(1) & vbCr
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
End With
Set DocNew = Documents.Add
With DocNew
  .Range.Text = StrOut
  .SaveAs2 FileName:="C:\Users\" & Environ("Username") & "\Desktop\i.txt", _
    FileFormat:=wdFormatText, AddToRecentFiles:=False
  .Close
End With
Set DocNew = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote