View Single Post
 
Old 01-12-2024, 06:42 PM
syl3786 syl3786 is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jan 2023
Posts: 97
syl3786 is on a distinguished road
Default

Quote:
Originally Posted by vivka View Post
Hi! Here is a simple option. I used some ideas from a Guessed's code (https://www.msofficeforums.com/179302-post6.html). You can modifiy the code to meet your needs. Maybe someone can suggest something more elegant.
Code:
Sub Repl_Digits_If()
'In the selected range, replace all single digits that start
'specifically indented paragraphs with asterisks.

Dim oRng As range
Dim oPar As Paragraph
Dim arrText() As String
Dim oDgt As range

Application.ScreenUpdating = False
Set oRng = selection.range
arrText = Split("zero one two three four five six seven eight nine", " ")

    For Each oPar In oRng.Paragraphs
        If oPar.range.ParagraphFormat.FirstLineIndent >= 0.5 And _
            oPar.range.Characters(1) Like "[0-9]*" And _
            oPar.range.Characters(2) Like "[!0-9]*" Then
                Set oDgt = oPar.range.Characters(1)
                oDgt.text = arrText(oDgt.text)
                oDgt.Font.ColorIndex = wdBrightGreen
        End If
    Next oPar
Application.ScreenUpdating = True
Set oRng = Nothing
End Sub
Thank you very much for your assistance. I have tested it and observed that the program only modifies the numbers "1" to "one" and "9" to "nine" if they appear in a document after identification of all numbers from 1 to 9.

The issue with the provided code is that it attempts to access array elements using the value of oDgt.Text, which is a string representing a single character. However, the Split function used to populate the arrText array expects a full string as input, not just a single character. As a result, the code is not able to correctly replace the digits with their corresponding words.
Reply With Quote