Consulting

Results 1 to 3 of 3

Thread: Macro in Word to Combine Text and Numbers

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

    Macro in Word to Combine Text and Numbers

    Hi all,

    Hope you all doing well.

    I need some little help here.

    I found the following code in the internet and seems to be partially working for what I need.

    I was wondering if the following code can be modified so it can bold the word "Chapter" with any number (could be any number from 1 up to 150) in the document.




    Thank you for your support.

    Sub Formatting_Chapter()
    Dim A(3) As String
    A(1) = "Chapter 1"
    A(2) = "Chapter 2"
    A(3) = "Chapter 3"
    For i = 1 To 3
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
           .Forward = True
           .Wrap = wdFindStop
           .Format = False
           .MatchCase = False
           .MatchWholeWord = False
           .MatchWildcards = False
           .MatchSoundsLike = False
           .MatchAllWordForms = False
           .Replacement.Font.Bold = True
           .Replacement.Font.ColorIndex = wdRed
          .Execute FindText:=A(i), ReplaceWith:=A(i), Format:=True, _
             Replace:=wdReplaceAll
    End With
    Next i
    End Sub

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You don't need VBA for this - it can all be done with a single wildcard Find/Replace, where:
    Find = Chapter [0-9]@>
    Replace = \1
    and you set the replacement font colour appropriately.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Regular
    Joined
    Apr 2011
    Posts
    72
    Location
    Hi Macropod, thank you for the code. Is working great! Much appreciated!

Posting Permissions

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