Public Function Convertir(Valor As String) As String
Dim Decimales As String
Dim Resultado As String
Dim Negativo As String
Dim Cent As String
    If IsNull(Valor) Then
        Exit Function
    Else
        If Not IsNumeric(Valor) Then
            Exit Function
        End If
    End If
   
    If Valor >= 1E+18 Then
        MsgBox "La cantidad introducida excede el lmite." & vbCrLf & "La cantidad mxima permitida es de un trilln.", vbInformation
    End If
   
    If Valor < 0 Then
        Negativo = "menos"
    End If
   
    'Separamos la parte entera de la decimal.
    Decimales = Mid(Format(Valor, "##0.00"), InStr(1, Format(Valor, "##0.00"), ",", vbTextCompare) + 1)
    Valor = Mid(Format(Valor, "##0.00"), 1, InStr(1, Format(Valor, "##0.00"), ",", vbTextCompare) - 1)
    If Valor < 0 Then
        Valor = -Valor
    End If
    If Valor < 1000000 Then
        Resultado = MenorMilio(Valor)
    End If
   
    If Valor >= 1000000 And Valor < 1000000000000# Then
        Resultado = MenorMilio(Int(Valor / 1000000)) & " "
        Resultado = Resultado & IIf(Int(Valor / 1000000) = 1, "milln", "millones")
        Resultado = Resultado & " " & MenorMilio(Valor - (Int(Valor / 1000000) * 1000000))
    End If
    If Valor >= 1000000000000# And Valor < 1E+18 Then
   
        Resultado = MenorMilio(Int(Valor / 1000000000000#)) & " "
        Resultado = Resultado & IIf(Int(Valor / 1000000000000#) = 1, "billn", "billones")
   
        If Valor - (Int(Valor / 1000000000000#) * 1000000000000#) >= 1000000 Then
            Resultado = Resultado & " " & MenorMilio(Int((Valor - (Int(Valor / 1000000000000#) * 1000000000000#)) / 1000000)) & " "
            Resultado = Resultado & IIf(Int((Valor - (Int(Valor / 1000000000000#) * 1000000000000#)) / 1000000) = 1, "milio", "milions")
            Resultado = Resultado & " " & MenorMilio((CDec(Valor) - (Int(Valor / 1000000000000#) * 1000000000000#)) - (Int((Valor - (Int(Valor / 1000000000000#) * 1000000000000#)) / 1000000) * 1000000))
        End If
        
        Resultado = Resultado & " " & MenorMilio(CDec(Valor) - (Int(Valor / 1000000000000#) * 1000000000000#))
    End If
    'Tratamiento de decimales
    If Decimales <> "" Then
        Decimales = MenorCent(Decimales)
    End If
   
    Resultado = Resultado & Switch(Round(Valor, 0) = 0, "", Valor < 2, " Euro", Valor >= 2, " Euros")
   
    'Con esta condicin controlo si es un cntimo o ms de uno
    Cent = IIf(Decimales <> "un", " cntimos", " cntimo")
  
    If Round(Valor, 0) = 0 Then
        Resultado = IIf(Decimales <> "", Decimales & Cent, "")
    Else
        Resultado = Resultado & IIf(Decimales <> "", " con " & Decimales & Cent, "")
    End If
   
    Resultado = IIf(Negativo <> "", Negativo & " ", "") & Resultado
   
    'Retorno el resultado en letras
    Convertir = Resultado
   
End Function

Public Function Menor21(Valor As String) As String
                 
         If Valor = 0 Then Menor21 = ""
         If Valor = 1 Then Menor21 = "un"
         If Valor = 2 Then Menor21 = "dos"
         If Valor = 3 Then Menor21 = "tres"
         If Valor = 4 Then Menor21 = "cuatro"
         If Valor = 5 Then Menor21 = "cinco"
         If Valor = 6 Then Menor21 = "seis"
         If Valor = 7 Then Menor21 = "siete"
         If Valor = 8 Then Menor21 = "ocho"
         If Valor = 9 Then Menor21 = "nueve"
         If Valor = 10 Then Menor21 = "diez"
         If Valor = 11 Then Menor21 = "once"
         If Valor = 12 Then Menor21 = "doce"
         If Valor = 13 Then Menor21 = "trece"
         If Valor = 14 Then Menor21 = "catorce"
         If Valor = 15 Then Menor21 = "quince"
         If Valor = 16 Then Menor21 = "dieciseis"
         If Valor = 17 Then Menor21 = "diecisiete"
         If Valor = 18 Then Menor21 = "dieciocho"
         If Valor = 19 Then Menor21 = "diecinueve"
         If Valor = 20 Then Menor21 = "veinte"
                 
End Function
Public Function MenorCent(Valor As String) As String
   
    If Val(Valor) <= 20 Then MenorCent = Menor21(Valor)
    If Val(Valor) > 20 And Val(Valor) < 30 Then MenorCent = "veinti" & Menor21(Valor - 20)
    If Val(Valor) = 30 Then MenorCent = "treinta"
    If Val(Valor) > 30 And Val(Valor) < 40 Then MenorCent = "treinta y " & Menor21(Valor - 30)
    If Val(Valor) = 40 Then MenorCent = "cuarenta"
    If Val(Valor) > 40 And Val(Valor) < 50 Then MenorCent = "cuarenta y " & Menor21(Valor - 40)
    If Val(Valor) = 50 Then MenorCent = "cincuenta"
    If Val(Valor) > 50 And Val(Valor) < 60 Then MenorCent = "cincuenta y " & Menor21(Valor - 50)
    If Val(Valor) = 60 Then MenorCent = "sesenta"
    If Val(Valor) > 60 And Val(Valor) < 70 Then MenorCent = "sesenta y " & Menor21(Valor - 60)
    If Val(Valor) = 70 Then MenorCent = "setenta"
    If Val(Valor) > 70 And Val(Valor) < 80 Then MenorCent = "setenta y " & Menor21(Valor - 70)
    If Val(Valor) = 80 Then MenorCent = "ochenta"
    If Val(Valor) > 80 And Val(Valor) < 90 Then MenorCent = "ochenta y " & Menor21(Valor - 80)
    If Val(Valor) = 90 Then MenorCent = "noventa"
    If Val(Valor) > 90 And Val(Valor) < 100 Then MenorCent = "noventa y " & Menor21(Valor - 90)
   
End Function
Public Function MenorMil(Valor As String) As String
    Dim numero As String  'Compruebo si el numero es 9, le cambio el formato a "nove" para las centenas
   
    If Valor < 100 Then MenorMil = MenorCent(Valor)
    If Valor = 100 Then MenorMil = "cien"
    If Valor > 100 And Valor < 200 Then MenorMil = "ciento " & MenorCent(Valor Mod 100)
   
    If Valor >= 200 Then
        numero = Menor21(Valor \ 100)
        Select Case numero
            Case "cinco"
                numero = "quiniento"
                MenorMil = numero & IIf(Valor > 199, "s", "") & " " & MenorCent(Valor Mod 100)
            Case "siete"
                numero = "sete"
                MenorMil = numero & "ciento" & IIf(Valor > 199, "s", "") & " " & MenorCent(Valor Mod 100)
            Case "nueve"
                numero = "nove"
                MenorMil = numero & "ciento" & IIf(Valor > 199, "s", "") & " " & MenorCent(Valor Mod 100)
            Case Else
                MenorMil = numero & "ciento" & IIf(Valor > 199, "s", "") & " " & MenorCent(Valor Mod 100)
        End Select
    End If
   
End Function
   
Public Function MenorMilio(Valor As String) As String
   
    If Valor < 1000 Then
        MenorMilio = MenorMil(Valor)
    End If
   
    If Valor = 1000 Then
        MenorMilio = "mil"
    End If
    If Valor > 1000 And Valor < 1000000 Then
        MenorMilio = IIf(Valor \ 1000 = 1, "mil ", MenorMil(Valor \ 1000) & " mil ") & MenorMil(Valor Mod 1000)
    End If
   
End Function