Search code examples
vbams-wordright-to-left

Inserting formatted numbers as text in Right to Left MS-Word document


I have sValA = 10/140/000 string.

Need inserting 10/140/000 as text in a right-to-left document.

When I performs below

ThisDocument.Bookmarks("Temp_GrandTotal").Range.Text = sValA

It returns 000/140/10

Any helps are appreciated.


Solution

  • You can add a UDF to swap the parts by a swap character. Then call it like:

    ThisDocument.Bookmarks("Temp_GrandTotal").Range.Text = SwapParts(sValA,"\")
    

    UDF code:

    Option Explicit
    
    Function SwapParts(ByVal sText As String, ByVal SwapChar As String) As String
        Dim oItems As Variant, oItem As Variant, sOutput As String
        oItems = Split(sText, SwapChar)
        For Each oItem In oItems
            If Len(sOutput) > 0 Then sOutput = SwapChar & sOutput
            sOutput = oItem & sOutput
        Next oItem
        SwapParts = sOutput
    End Function