![]() |
|
#1
|
||||
|
||||
![]()
I made mistake in step 5.
I corrected it. I actually want to find plain number after "US " Initially I tried removing all commas But I didn't realize it will remove all commas from large doccument containing other text also. Apology for changing the question. Step 5 is making document again at original state. |
#2
|
||||
|
||||
![]()
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] |
#3
|
||||
|
||||
![]()
Solved My all other problems with respect to find and replace as well as find copy and paste.
I have to do lot of find and replace and i record macro for that which some times exceeds line limits. Now i simply follow your above find and replace whic will save lot of lines. |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
konopca | Word VBA | 5 | 02-20-2014 02:34 PM |
![]() |
khalidfazeli | Excel | 2 | 02-06-2013 09:38 AM |
![]() |
jperez84 | Word VBA | 24 | 09-20-2012 11:34 AM |
![]() |
jperez84 | Word VBA | 10 | 09-19-2012 04:48 PM |
Trying to find and copy all headings at the same time | WaltR | Word | 7 | 08-21-2012 03:12 PM |