PDA

View Full Version : Find/Replace Wildcard to Sort Numbers in Word



rsrasc
01-28-2023, 03:12 PM
Hi all,

Just wondering if there is a simple find and replace wildcard to sort text in numerical order.

The below code is working fine but I'm looking for something simple.

Thank you for any help.

Cheers!




Sub Macro7()
' Macro7 Macro
Selection.WholeStory
Selection.Sort ExcludeHeader:=False, FieldNumber:="Paragraphs", SortFieldType:=wdSortFieldNumeric,
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

gmayor
01-29-2023, 01:15 AM
Why do you even need a macro for this, when Word has effective tools built-in to sort numbers?

rsrasc
01-29-2023, 04:32 AM
Hi Mr. Mayor,

Thank you for your response. Even when I recorded the action to sort numbers I was hoping that with a wildcard I could accomplish the same. By having a wildcard to do that I was hoping I could incorporate it with the rest of my macros to automate what I'm want to accomplish without having to input five (5) different wildcards. I'm not against using wildcards but having the ability to use macros I must say will save me some time especially when this is a repetitive thing that I'm doing with my current document which is over 2000 pages. A F/R wildcard will help me in the process.

Cheers!



Sub All_Macros()
Call Macro1
Call Macro2
Call Macro3
Call Macro4
End Sub

Sub Macro1()
' Macro2 Macro
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Sub Macro2()
' Macro2 Macro
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "( )([0-9]@?[A-Za-z])"
.Replacement.Text = "^p\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Sub Macro3()
'This macro will highlight all the numbers in blue
Selection.Find.ClearFormatting
Selection.Find.Highlight = False
Selection.Find.Replacement.ClearFormatting
'Selection.Find.Replacement.Font = True
With Selection.Find
.Text = "([0-9])"
.Replacement.Text = "\1"
.Replacement.Font.Name = "Tahoma"
.Replacement.Font.Size = "9"
.Replacement.Font.Bold = True
.Replacement.Font.Italic = False
.Replacement.Font.ColorIndex = wdBlue
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Sub Macro4()
'This macro will highlight all the text in this document in red AND does exclude numbers
Selection.Find.ClearFormatting
Selection.Find.Highlight = False
Selection.Find.Replacement.ClearFormatting
'Selection.Find.Replacement.Font = True
With Selection.Find
.Text = "([A-Za-z]@?[!\;\?\:\,\""\.])"
.Replacement.Text = "\1"
.Replacement.Font.Name = "Tahoma"
.Replacement.Font.Size = "12"
.Replacement.Font.Italic = False
.Replacement.Font.ColorIndex = wdRed
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll
End Sub


Sub Macro18()
' Macro2 Macro
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13([A-Za-z])"
.Replacement.Text = "^1\1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub