-
۱۷ خرداد ماه ۱۴۰۱ ساعت ۱۳:۵۱ دقیقه
-
کاربر شماره ۲۵۱۰۰۳
-
با عرض سلام و احترام
یک نمونه ماکرو جهت تبدیل اعداد به معادل حروف در اکسل که می بایست با کمی تغییر بومی سازی گردد :Option Explicit 'Main Function Function SpellNumber(ByVal MyNumber) Dim Dollars, Cents, Temp Dim DecimalPlace, Count ReDim Place(9) As String Place(2) = " åÒÇÑ " Place(3) = " ãíáíæä " Place(4) = " ãíáíÇÑÏ " Place(5) = " ÊÑíáíæä " MyNumber = Trim(Str(MyNumber)) DecimalPlace = InStr(MyNumber, ".") If DecimalPlace > 0 Then Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _ "00", 2)) MyNumber = Trim(Left(MyNumber, DecimalPlace - 1)) End If Count = 1 Do While MyNumber <> "" Temp = GetHundreds(Right(MyNumber, 3)) If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars If Len(MyNumber) > 3 Then MyNumber = Left(MyNumber, Len(MyNumber) - 3) Else MyNumber = "" End If Count = Count + 1 Loop Select Case Dollars Case "" Dollars = "" Case "One" Dollars = "" Case Else Dollars = Dollars & "" End Select Select Case Cents Case "" Cents = "" Case "One" Cents = "" Case Else Cents = "" & Cents & "" End Select SpellNumber = Dollars & Cents End Function Function GetHundreds(ByVal MyNumber) Dim Result As String If Val(MyNumber) = 0 Then Exit Function MyNumber = Right("000" & MyNumber, 3) ' Convert the hundreds place. If Mid(MyNumber, 1, 1) <> "0" Then Result = GetDigit(Mid(MyNumber, 1, 1)) & " ÕÏ " End If ' Convert the tens and ones place. If Mid(MyNumber, 2, 1) <> "0" Then Result = Result & GetTens(Mid(MyNumber, 2)) Else Result = Result & GetDigit(Mid(MyNumber, 3)) End If GetHundreds = Result End Function Function GetTens(TensText) Dim Result As String Result = "" ' Null out the temporary function value. If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19... Select Case Val(TensText) Case 10: Result = "Ïå" Case 11: Result = "íÇÒÏå" Case 12: Result = "ÏæÇÒÏå" Case 13: Result = "ÓíÒÏå" Case 14: Result = "åÇÑÏå" Case 15: Result = "ÇäÒÏå" Case 16: Result = "ÔÇäÒÏå" Case 17: Result = "åÝÏå" Case 18: Result = "åÌÏå" Case 19: Result = "äæÒÏå" Case Else End Select Else ' If value between 20-99... Select Case Val(Left(TensText, 1)) Case 2: Result = "ÈíÓÊ " Case 3: Result = "Óí " Case 4: Result = "åá " Case 5: Result = "äÌÇå " Case 6: Result = "ÔÕÊ " Case 7: Result = "åÝÊÇÏ " Case 8: Result = "åÔÊÇÏ " Case 9: Result = "äæÏ " Case Else End Select Result = Result & GetDigit _ (Right(TensText, 1)) ' Retrieve ones place. End If GetTens = Result End Function Function GetDigit(Digit) Select Case Val(Digit) Case 1: GetDigit = "í˜" Case 2: GetDigit = "Ïæ" Case 3: GetDigit = "Óå" Case 4: GetDigit = "åÇÑ" Case 5: GetDigit = "äÌ" Case 6: GetDigit = "ÔÔ" Case 7: GetDigit = "åÝÊ" Case 8: GetDigit = "åÔÊ" Case 9: GetDigit = "äå" Case Else: GetDigit = "" End Select End Function
-