Consulting

Results 1 to 3 of 3

Thread: Find/Replace Wildcard to Sort Numbers in Word

  1. #1
    VBAX Regular
    Joined
    Apr 2011
    Posts
    72
    Location

    Find/Replace Wildcard to Sort Numbers in Word

    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

  2. #2
    Why do you even need a macro for this, when Word has effective tools built-in to sort numbers?
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Apr 2011
    Posts
    72
    Location
    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
    Last edited by Aussiebear; 01-29-2023 at 10:08 AM. Reason: Reduced whitespace

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •