VB-AN-IZ
09-10-2016, 07:59 AM
What's the simplest macro for isolating the first word or cell from each paragraph, and removing everything else from the document? I need this for a list of names - as in, this:
Joe Blow
John Doe
...would become:
Joe
John
I recorded a really idiotic macro that separated each space into a separate column, then copied/pasted just the first column. But it doesn't always work, and I'm sure there's an easier way...
Selection.WholeStory
Application.DefaultTableSeparator = " "
Selection.ConvertToTable Separator:=wdSeparateByDefaultListSeparator, _
NumColumns:=5, NumRows:=45, AutoFitBehavior:=wdAutoFitFixed
With Selection.Tables(1)
.Style = "Table Grid"
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
End With
Selection.HomeKey Unit:=wdStory
Selection.HomeKey Unit:=wdRow
Selection.EndKey Unit:=wdColumn, Extend:=True
Selection.Copy
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdFormatPlainText)
Selection.WholeStory
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 _
:=wdEnglishAUS, SubFieldNumber:="Paragraphs", SubFieldNumber2:= _
"Paragraphs", SubFieldNumber3:="Paragraphs"
Selection.HomeKey Unit:=wdStory
End Sub
Joe Blow
John Doe
...would become:
Joe
John
I recorded a really idiotic macro that separated each space into a separate column, then copied/pasted just the first column. But it doesn't always work, and I'm sure there's an easier way...
Selection.WholeStory
Application.DefaultTableSeparator = " "
Selection.ConvertToTable Separator:=wdSeparateByDefaultListSeparator, _
NumColumns:=5, NumRows:=45, AutoFitBehavior:=wdAutoFitFixed
With Selection.Tables(1)
.Style = "Table Grid"
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
End With
Selection.HomeKey Unit:=wdStory
Selection.HomeKey Unit:=wdRow
Selection.EndKey Unit:=wdColumn, Extend:=True
Selection.Copy
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdFormatPlainText)
Selection.WholeStory
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 _
:=wdEnglishAUS, SubFieldNumber:="Paragraphs", SubFieldNumber2:= _
"Paragraphs", SubFieldNumber3:="Paragraphs"
Selection.HomeKey Unit:=wdStory
End Sub