VBA to Applescript for Excel 2008

Hello,
I 've found and edited a VBA for my work. but now i cant use it with our MacBook Pro. it has Office 2008 for Mac and it says " Office for Mac does not support VBA script ".

Anyone can help me to convert this script to Applescript?!

Thanks for any help!..

'****************
’ Main Function *
'****************
Function Cevir(ByVal MyNumber)

Dim Riyals, Baisa, Temp
Dim DecimalPlace, Count

ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "

' String representation of amount
MyNumber = Trim(Str(MyNumber))

' Position of decimal place 0 if none
DecimalPlace = InStr(MyNumber, ".")
'Convert cents and set MyNumber to dollar amount
If DecimalPlace > 0 Then
    'Baisa = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
    Baisa = GetHundreds(Left(Mid(MyNumber, DecimalPlace + 1) & "000", 3))
    MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If

Count = 1
Do While MyNumber <> ""
   Temp = GetHundreds(Right(MyNumber, 3))
   If Temp <> "" Then Riyals = Temp & Place(Count) & Riyals
      If Len(MyNumber) > 3 Then
         MyNumber = Left(MyNumber, Len(MyNumber) - 3)
    Else
        MyNumber = ""
    End If
    Count = Count + 1
Loop

Select Case Riyals
    Case ""
        Riyals = ""
    Case "One"
        Riyals = "One Riyal"
    Case Else
        Riyals = Riyals & " Riyals"
End Select

If Riyals = "" Then
    Select Case Baisa
        Case ""
            'Baisa = " and No Baisa"
            Baisa = ""
        Case "One"
            Baisa = "One Baisa"
        Case Else
            Baisa = Baisa & " Baisa"
    End Select
Else
    Select Case Baisa
        Case ""
            'Baisa = " and No Baisa"
            Baisa = ""
        Case "One"
            Baisa = " and One Baisa"
        Case Else
            Baisa = " and " & Baisa & " Baisa"
    End Select
End If

Cevir = Riyals & Baisa

End Function

'*******************************************
’ Converts a number from 100-999 into text *
'*******************************************
Private 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)) & " Hundred "
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

'*********************************************
’ Converts a number from 10 to 99 into text. *
'*********************************************
Private 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 = "Ten"
        Case 11: Result = "Eleven"
        Case 12: Result = "Twelve"
        Case 13: Result = "Thirteen"
        Case 14: Result = "Fourteen"
        Case 15: Result = "Fifteen"
        Case 16: Result = "Sixteen"
        Case 17: Result = "Seventeen"
        Case 18: Result = "Eighteen"
        Case 19: Result = "Nineteen"
        Case Else
    End Select
  Else                                 ' If value between 20-99
    Select Case Val(Left(TensText, 1))
        Case 2: Result = "Twenty "
        Case 3: Result = "Thirty "
        Case 4: Result = "Forty "
        Case 5: Result = "Fifty "
        Case 6: Result = "Sixty "
        Case 7: Result = "Seventy "
        Case 8: Result = "Eighty "
        Case 9: Result = "Ninety "
        Case Else
    End Select
     Result = Result & GetDigit _
        (Right(TensText, 1))  'Retrieve ones place
  End If
  GetTens = Result

End Function

'*******************************************
’ Converts a number from 1 to 9 into text. *
'*******************************************
Private Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = “One”
Case 2: GetDigit = “Two”
Case 3: GetDigit = “Three”
Case 4: GetDigit = “Four”
Case 5: GetDigit = “Five”
Case 6: GetDigit = “Six”
Case 7: GetDigit = “Seven”
Case 8: GetDigit = “Eight”
Case 9: GetDigit = “Nine”
Case Else: GetDigit = “”
End Select
End Function

You’ll probably have more luck taking a stab at it in AppleScript yourself and posting the specific issues you’re having for something this complex.

Or, alternatively, just describe what you are trying to do…sometimes folks surprise with not just help, but finished scripts. I’m personally always floored when that happens, and wish I had the time to give back at that level!

This Script convert Qatar Currency rate to words. for example, if i write 123,456 it says One Hundred Twenty Three Riyals and Four Hundred Fifty Six Baisas.

Hi,

try this:


property oneToNineList : {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"}
property tenToNineteenList : {"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"}
property twentyToNinetyList : {"", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}
property thousendToTrillionList : {"", " Thousand ", " Million ", " Billion", " Trillion"}
property currency : "Riyal"
property currency_cent : "Baisa"

say convertNumberToWords(123.456)

on convertNumberToWords(theNumber)
	if (theNumber as text) contains "E" then
		set textNumber to theNumber as text
		set o to offset of "E" in textNumber
		set exponent to text (o + 2) thru -1 of textNumber as integer
		tell textNumber to set {intValue, modValue} to {(text 1 thru (exponent + 2) as real) * (10 ^ exponent), text (exponent + 3) thru (o - 1)}
		if modValue ends with "E" then
			set modValue to 0
		else
			set modValue to modValue as integer
		end if
	else
		tell theNumber to set {intValue, modValue, countMod} to {it div 1, it mod 1, (count (it mod 1 as text)) - 2}
		set modValue to ((modValue * (10 ^ countMod)) as integer) div 1
	end if
	if modValue is 0 and intValue = 0 then return ""
	set intWords to ""
	if intValue is not 0 then
		set x to 1
		repeat until intValue = 0
			set intWords to GetHundreds(intValue mod 1000) & item x of thousendToTrillionList & intWords
			set x to x + 1
			set intValue to intValue div 1000
		end repeat
	end if

	if intWords = "One" then
		set intWords to "One " & currency
	else if intWords is not "" then
		set intWords to intWords & space & currency & "s"
	end if
	
	if (count modValue as text) = 1 then set modValue to modValue * 10
	set modWords to GetHundreds(modValue)

	if modWords is not "" and intWords is not "" then
		set modWords to " and " & modWords & space & currency_cent
	else if modWords is not "" and intWords is "" then
		set modWords to modWords & space & currency_cent
	end if
	return intWords & modWords
end convertNumberToWords

on GetHundreds(numValue)
	if numValue > 99 then
		return GetDigit(numValue div 100) & " Hundred " & GetTens(numValue mod 100)
	else
		return GetTens(numValue)
	end if
end GetHundreds

on GetTens(TT)
	if TT < 10 then
		return GetDigit(TT)
	else if TT < 20 then
		return item (TT - 9) of tenToNineteenList
	else
		return item (TT div 10) of twentyToNinetyList & item ((((TT mod 10) = 0) as integer) + 1) of {" ", ""} & GetDigit(TT mod 10)
	end if
end GetTens

on GetDigit(Digit)
	return item (Digit + 1) of oneToNineList
end GetDigit

Thanks so much, i ll try this and report back.

erm… how can i add this script to the Excel ? i cant find editor thingy in Excel 2008 for Mac. should i use any other program to make that script ?

enable the script menu in /Applictions/AppleScript/AppleScript Utility,
put your script in (~)/Library/Scripts and run it from the script menu