Sub chupapalepega()
'
' chupapalepega Macro
'
'
Sub ConvertirLetrasANumero()
Dim rng As Range
Dim texto As String
Dim palabras() As String
Dim total As Long, temporal As Long
Dim i As Integer
If Selection.Type = wdSelectionNormal Then
Set rng = Selection.Range
texto = LCase(Trim(rng.Text))
palabras = Split(texto, " ")
For i = LBound(palabras) To UBound(palabras)
Select Case palabras(i)
' Unidades
Case "uno", "un": temporal = temporal + 1
Case "dos": temporal = temporal + 2
Case "tres": temporal = temporal + 3
Case "cuatro": temporal = temporal + 4
Case "cinco": temporal = temporal + 5
Case "seis": temporal = temporal + 6
Case "siete": temporal = temporal + 7
Case "ocho": temporal = temporal + 8
Case "nueve": temporal = temporal + 9
' Especiales y Decenas
Case "ochenta": temporal = temporal + 80
Case "ochenta y uno": temporal = temporal + 81
Case "ochenta y dos": temporal = temporal + 82
Case "ochenta y tres": temporal = temporal + 83
Case "ochenta y cuatro": temporal = temporal + 84
Case "ochenta y cinco": temporal = temporal + 85
Case "ochenta y seis": temporal = temporal + 86
Case "ochenta y siete": temporal = temporal + 87
Case "ochenta y ocho": temporal = temporal + 88
Case "ochenta y nueve": temporal = temporal + 89
' Centenas
Case "cien", "ciento": temporal = temporal + 100
Case "doscientos": temporal = temporal + 200
Case "quinientos": temporal = temporal + 500
' Multiplicadores
Case "mil":
If temporal = 0 Then temporal = 1
total = total + (temporal * 1000)
temporal = 0
End Select
Next i
total = total + temporal
rng.Text = CStr(total)
Else
MsgBox "Por favor, selecciona el texto (ej. 'ciento veinte')."
End If
End Sub