Saturday, August 1, 2026
Home Hackathon VB Code to convert Digit to Text in MS Word Document

VB Code to convert Digit to Text in MS Word Document

Copy the code below by creating a new Macro to convert:

To add shortcut for this macro, you shall follow this article that I’ve written in prior.

Sub DigitToText()
    Dim datasagar_Digits As String
    Dim datasagar_NumText As String

    datasagar_NumText = ""

    ' Select Number from Word Document 
    Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdMove
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend

    ' Store digits in variable named datasagar_Digits
    datasagar_Digits = Trim(Selection.Text)

    If Val(datasagar_Digits) > 999999 Then
        If Val(datasagar_Digits) <= 999999999 Then
            datasagar_NumText = Trim(Int(Str(Val(datasagar_Digits) / 1000000)))
            ' For selection range, create a field containing the digits and the cardtext format flag
            Selection.Fields.Add Range:=Selection.Range, _
              Type:=wdFieldEmpty, Text:="= " + datasagar_NumText + " \* CardText", _
              PreserveFormatting:=True

            ' Select the previously created field and copy it
            Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
            datasagar_NumText = Selection.Text & " million "
            datasagar_Digits = Right(datasagar_Digits, 6)
        End If
    End If
    If Val(datasagar_Digits) <= 999999 Then
        ' Create a field containing that digits and the cardtext format flag
        Selection.Fields.Add Range:=Selection.Range, _
          Type:=wdFieldEmpty, Text:="= " + datasagar_Digits + " \* CardText", _
          PreserveFormatting:=True

        ' Select the field and copy it
        Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
        datasagar_Digits = datasagar_NumText & Selection.Text

        ' Replace number with words in the selected area of word document
        Selection.TypeText Text:=datasagar_Digits
        Selection.TypeText Text:=" "
    Else
        MsgBox "Number too large", vbOKOnly
    End If
End Sub

datasagarhttp://www.DataSagar.com
The author of this blog post is a technology fellow, an IT entrepreneur, and Educator in Kathmandu Nepal. With his keen interest in Data Science and Business Intelligence, he writes on random topics occasionally in the DataSagar blog.
RELATED ARTICLES

Risks of Frontier AI in Agent driven world | Should Governments Slow Down AI Development?

Should governments slow AI development? Explore frontier AI risks, job automation, national security concerns, and global AI regulation efforts.

Meta to Deploy Nepal’s First Direct Point of Presence (PoP) Data Center in Kathmandu

Matt Jensen, a representative from Meta, announced that Meta will deploy its own dedicated Point of Presence (PoP) infrastructure in Nepal at Data World’s Tier-3 Data Center located in Matatirthha, Kathmandu, targeted for completion by late 2026.

How to setup DNS Records in Cloudflare – Guide for Website Owners

Whether you're launching your first website, connecting a custom email address, or moving your domain to a new hosting provider, you've probably...

Most Popular

Risks of Frontier AI in Agent driven world | Should Governments Slow Down AI Development?

Should governments slow AI development? Explore frontier AI risks, job automation, national security concerns, and global AI regulation efforts.

Meta to Deploy Nepal’s First Direct Point of Presence (PoP) Data Center in Kathmandu

Matt Jensen, a representative from Meta, announced that Meta will deploy its own dedicated Point of Presence (PoP) infrastructure in Nepal at Data World’s Tier-3 Data Center located in Matatirthha, Kathmandu, targeted for completion by late 2026.

How to setup DNS Records in Cloudflare – Guide for Website Owners

Whether you're launching your first website, connecting a custom email address, or moving your domain to a new hosting provider, you've probably...

DeepSeek AI: The Open-Source AI Disruptor Shaking Up the Tech World

DeepSeek AI is revolutionizing the artificial intelligence landscape with its open-source, cost-effective, and highly customizable model. Built on cutting-edge transformer architecture and fine-tuned using reinforcement learning with human feedback (RLHF), DeepSeek delivers human-like text generation and accurate responses. Its efficient training techniques reduce computational costs by up to 40%, while its foundation on open-source frameworks like PyTorch and TensorFlow ensures seamless integration for developers. Whether you're a startup, a developer, or a large enterprise, DeepSeek offers unparalleled transparency, affordability, and performance, making it a game-changer in the world of AI. Discover why DeepSeek is outshining competitors like ChatGPT and Google Gemini in this comprehensive guide.