Function ALETRAS(Numero As Double, Optional DecimalEnLetra As Boolean) As String
'Declaracion de variables Dim Moneda As String Dim Monedas As String Dim Centavo As String Dim Centavos As String Dim Con As String Dim NumCentavos As Double Dim Letra As String Const Maximo = 1999999999.99 ' Parmetros Moneda = "Peso" Monedas = "Pesos" Decimal1 = "Centavo" Decimales = "Centavos" Con = "Con" 'Si el numero esta dentro de 0 y 1999999999.99 (Maximo) entonces 'convertir el numero a letras If (Numero >= 0) And (Numero <= Maximo) Then Letra = LETRAS((Fix(Numero))) 'Si solo es un numero entonces 'agregar la moneda en singular If (Numero = 1) Then Letra = Letra & " " & Moneda 'De lo contrario agregar la moneda en plural Else Letra = Letra & " " & Monedas End If NumCentavos = Round((Numero - Fix(Numero)) * 100) 'Pasar a decimales (al n umero le resta el numero entero y lo multiplica por 100) 'Si los centvos son mayores a cero entonces If NumCentavos >= 0 Then 'Si el parmetro DecimalEnLetra es VERDADERO If DecimalEnLetra Then 'Convertir los centavos en letra Letra = Letra & " " & Con & " " & LETRAS(Fix(NumCentavos)) 'Si el centavo es uno agregar leyenda Centavo (Singular) If (NumCentavos = 1) Then Letra = Letra & " " & Decimal1 'De lo contrario agregar la leyenda Centavos (Plural) Else Letra = Letra & " " & Decimales End If 'De lo contrario mostrar los centecimos como nmero Else 'Si los centavos son menores a 10 entonces
If NumCentavos < 10 Then
Letra = Letra & " " & Con & " " & " 0" & NumCentavos & "/100" Else 'De lo contrario Letra = Letra & " " & Con & " " & NumCentavos & "/100" End If End If End If 'Regresar el resultado final de la conversin ALETRAS = Letra Else 'Si el Numero no est dentro de los lmites mostrar un mensaje de error ALETRAS = "ERROR: el importe esta fuera del lmite." End If End Function 'Funcion LETRAS Function LETRAS(Numero As Long) As String 'Declaracion de las variables Dim Unidades, Decenas, Centenas Dim Resultado As String 'Numeros en letras Unidades = Array("", "Un", "Dos", "Tres", "Cuatro", "Cinco", "Seis", "Siete", "O cho", "Nueve", "Diez", "Once", "Doce", "Trece", "Catorce", "Quince", "Diecisis", "Diecisiete", "Dieciocho", "Diecinueve", "Veinte", "Veintiuno", "Veintidos", "Ve intitres", "Veinticuatro", "Veinticinco", "Veintiseis", "Veintisiete", "Veintioc ho", "Veintinueve") Decenas = Array("", "Diez", "Veinte", "Treinta", "Cuarenta", "Cincuenta", "Sesen ta", "Setenta", "Ochenta", "Noventa", "Cien") Centenas = Array("", "Ciento", "Doscientos", "Trescientos", "Cuatrocientos", "Qu inientos", "Seiscientos", "Setecientos", "Ochocientos", "Novecientos") Select Case Numero Case 0 Resultado = "Cero" Case 1 To 29 Resultado = Unidades(Numero) Case 30 To 100 Resultado = Decenas(Numero \ 10) + IIf(Numero Mod 10 <> 0, " y " + LETRA S(Numero Mod 10), "") Case 101 To 999 Resultado = Centenas(Numero \ 100) + IIf(Numero Mod 100 <> 0, " " + LETR AS(Numero Mod 100), "") Case 1000 To 1999 Resultado = "Mil" + IIf(Numero Mod 1000 <> 0, " " + LETRAS(Numero Mod 10 00), "") Case 2000 To 999999 Resultado = LETRAS(Numero \ 1000) + " Mil" + IIf(Numero Mod 1000 <> 0, " " + LETRAS(Numero Mod 1000), "") Case 1000000 To 1999999 Resultado = "Un Milln" + IIf(Numero Mod 1000000 <> 0, " " + LETRAS(Numero Mod 1000000), "") Case 2000000 To 1999999999 Resultado = LETRAS(Numero \ 1000000) + " Millones" + IIf(Numero Mod 1000