sugarmaker
Programmer
Here is the goal: Using Word 2003, Find if a file has duplicate strings that match the regular expression: “CAD[0-9]@.[0-9]@>". The target string example is: CAD200709273579.86. The number of records will be 10-100 typically.
I recorded a macro to search the file, highlight then copy the hits, open a new doc, paste the selection then sort ascending text. With a quick visual inspection, dups are obvious. Not ideal but effective. And it works
Problem: it only works once. The macro will not execute after the recording. It bombs on
“Selection.Copy”. Also I’d really like a dialog box to pop and say. “xx number of Duplicate found” or “No Duplicates found”
Thanks help is appreciated
.
Sub Sample()
'
' Sample Macro
' Macro recorded 10/25/2007
'
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "CAD[0-9]@.[0-9]@>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Copy
Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
Selection.PasteAndFormat (wdPasteDefault)
Selection.HomeKey Unit:=wdStory
Selection.Sort ExcludeHeader:=False, FieldNumber:="Paragraphs", _
SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, _
FieldNumber2:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
wdSortSeparateByTabs, SortColumn:=False, CaseSensitive:=False, LanguageID _
:=wdEnglishUS, SubFieldNumber:="Paragraphs", SubFieldNumber2:= _
"Paragraphs", SubFieldNumber3:="Paragraphs"
End Sub
I recorded a macro to search the file, highlight then copy the hits, open a new doc, paste the selection then sort ascending text. With a quick visual inspection, dups are obvious. Not ideal but effective. And it works
Problem: it only works once. The macro will not execute after the recording. It bombs on
“Selection.Copy”. Also I’d really like a dialog box to pop and say. “xx number of Duplicate found” or “No Duplicates found”
Thanks help is appreciated
.
Sub Sample()
'
' Sample Macro
' Macro recorded 10/25/2007
'
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "CAD[0-9]@.[0-9]@>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Copy
Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
Selection.PasteAndFormat (wdPasteDefault)
Selection.HomeKey Unit:=wdStory
Selection.Sort ExcludeHeader:=False, FieldNumber:="Paragraphs", _
SortFieldType:=wdSortFieldAlphanumeric, SortOrder:=wdSortOrderAscending, _
FieldNumber2:="", SortFieldType2:=wdSortFieldAlphanumeric, SortOrder2:= _
wdSortOrderAscending, FieldNumber3:="", SortFieldType3:= _
wdSortFieldAlphanumeric, SortOrder3:=wdSortOrderAscending, Separator:= _
wdSortSeparateByTabs, SortColumn:=False, CaseSensitive:=False, LanguageID _
:=wdEnglishUS, SubFieldNumber:="Paragraphs", SubFieldNumber2:= _
"Paragraphs", SubFieldNumber3:="Paragraphs"
End Sub