MS Office Forum / Word / Programming / March 2005
Change $ to Local Currency
|
|
Thread rating:  |
prkhan56 - 20 Feb 2005 06:38 GMT Hello All, I am using Office 2003 and have the following problem: I use the following macro to convert currency to Word
The macro does the following:
$1,234.50 - converts to One Thousand Two Hundred Thirty Four Dollars and Fifty Cents ($1,234.50)
I wish to change - the $ to IRS (our local currency) - Dollars to Rupees - Cents to Paise - It should show the numeric value as IRS 1,234.50 (without bracket and in the beginning, instead of the end) followed by One Thousand Two Hundred Thirty Four Rupees and Fifty Paise (in brackets).
Any help would be greatly appreciated.
TIA
Rashid Khan
Jean-Guy Marcil - 21 Feb 2005 15:35 GMT prkhan56 was telling us: prkhan56 nous racontait que :
> Hello All, > I am using Office 2003 and have the following problem: [quoted text clipped - 4 lines] > $1,234.50 - converts to One Thousand Two Hundred Thirty Four Dollars > and Fifty Cents ($1,234.50) And where is that macro?
> I wish to change > - the $ to IRS (our local currency) [quoted text clipped - 9 lines] > > Rashid Khan
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
prkhan56 - 22 Feb 2005 13:47 GMT Sorry... I missed it.. I am posting it here Sub NumConv() ' ' Macro created 1/18/05 by Oper 'This macro will convert Numeric to Word in MS Word ' Dim vOrigNum As String, vOrigNumPercent As String, vDollar As Integer Dim vPercent As Integer, vDecimal As Integer, vStrLeft As String Dim vStrLeftLen As Integer, vStrRight As String, vStrRightLen As Integer Dim vStrChar As String, vStrHoldStr As String, vStrHoldStrLen As Integer Dim vStrLeftMil As String, vStrLeftBil As String Dim vStrLeftThou As String, vSrrLeftHun As String Dim vClearSpace As String
If Selection.Type = wdSelectionIP Then 'Selects numbers to left of IP Selection.MoveStartWhile Cset:="0123456789$%.,-", Count:=wdBackward End If
vOrigNum = Selection.Text 'Assigns selection to variable vOrigNumLen = Len(vOrigNum) 'Sets length of selected number to variable vDollar = InStr(1, vOrigNum, "$") 'Checks to see if number is dollar figure vPercent = InStr(1, vOrigNum, "%") 'Checks to see if number is a percent vMinus = InStr(1, vOrigNum, "-") 'Checks to see if number is negative
If vMinus <> 0 Then If vDollar <> 0 Then 'If a dollar amount, then Caps; otherwise, lowercase Selection.TypeText Text:="Minus " 'Types Minus if no. is negative Else Selection.TypeText Text:="minus " 'Types minus if no. is negative End If End If
For i = 1 To vOrigNumLen 'Strips all but numbers from variable vStrChar = Mid$(vOrigNum, i, 1) Select Case vStrChar Case ",", "$", "%", "-" Case Else vStrHoldStr = vStrHoldStr & vStrChar End Select 'Stripped number assigned to new variable Next i
vStrHoldStrLen = Len(vStrHoldStr) 'Checks length of stripped number vDecimal = InStr(1, vStrHoldStr, ".") 'Checks to see if number includes decimal
'If number includes decimal, assigns zeros if needed to the left or right If vDecimal <> 0 Then vStrLeft = Mid(vStrHoldStr, 1, vDecimal - 1) If vStrLeft = "" Then vStrLeft = "0" 'Adds left zero for ".87" type number End If If vStrHoldStrLen - vDecimal = "0" Then vStrRight = "0" 'Adds right zero for "87." type number If vDollar <> 0 Then vStrRight = "00" 'Adds two zeros for "$87." type number Else vStrRight = Mid(vStrHoldStr, vDecimal + 1, vStrHoldStrLen - vDecimal) End If 'Assigns actual numbers to vStrRight if they exist End If
If vDecimal = 0 Then 'If there is no decimal, assigns number to vStrLeft vStrLeft = vStrHoldStr vStrRight = "0" 'and adds 0 or 00, as appropriate, to vStrRight If vDollar <> 0 Then vStrRight = "00" End If
vStrLeftLen = Len(vStrLeft) 'Assigns length of vStrLeft to vStrLeftLen
If vStrLeftLen > 12 Then GoTo GreaterThanBillion 'If > billion, exit
'If billions, strip billions string and insert into doc using Field If vStrLeftLen > 9 Then 'Start at position 1, move right Length - 9 positions vStrLeftBil = Mid(vStrLeft, 1, vStrLeftLen - 9) 'Assign leftover string to vStrLeft, start at Length-8, move 9 positions vStrLeft = Mid(vStrLeft, vStrLeftLen - 8, 9) vStrLeftLen = Len(vStrLeft) If vDollar <> 0 Then 'If a dollar amount, then Caps; otherwise, lowercase Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " + vStrLeftBil + " \* CardText \* Caps", _ PreserveFormatting:=True Selection.TypeText Text:=" Billion " Else Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " + vStrLeftBil + " \* CardText", _ PreserveFormatting:=True Selection.TypeText Text:=" billion " End If Else GoTo CheckMillions 'If no billions, check millions End If
CheckMillions: 'If millions, strip millions string and insert into doc using Field If vStrLeftLen > 6 Then 'Start at position 1, move right Length - 6 positions vStrLeftMil = Mid(vStrLeft, 1, vStrLeftLen - 6) 'Assign leftover string to vStrLeft, start Length-5, move 6 positions vStrLeft = Mid(vStrLeft, vStrLeftLen - 5, 6) vStrLeftLen = Len(vStrLeft) 'If there is no millions, go to thousands If vStrLeftMil = "000" Then GoTo DoThousands End If 'If a dollar amount, then Caps; otherwise, lowercase If vDollar <> 0 Then Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " + vStrLeftMil + " \* CardText \* Caps ", _ PreserveFormatting:=True Selection.TypeText Text:=" Million " Else Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " + vStrLeftMil + " \* CardText ", _ PreserveFormatting:=True Selection.TypeText Text:=" million " End If Else GoTo DoThousands 'If no millions, do hundred thousands End If
DoThousands: 'If decimal, but not dollar, insert thousands, but skip if 0 If vDecimal <> 0 And vDollar = 0 And vStrLeft <> "000000" Then Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " + vStrLeft + " \* CardText", _ PreserveFormatting:=True 'Removed \* Caps to use lowercase End If 'If decimal, but not dollar, insert left/right Fields using "point" If vDecimal <> 0 And vDollar = 0 Then vClearSpace = ClearExtraSpace() 'Deletes extra space in "millions" Selection.TypeText " point " vStrRightLen = Len(vStrRight) For i = 1 To vStrRightLen 'Individually insert each right side number Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " + Mid(vStrRight, i, 1) + " \* CardText", _ PreserveFormatting:=True 'Removed \* Caps to use lowercase Selection.TypeText Text:=" " Next i Selection.TypeBackspace End If
'If not decimal, and not dollar, just insert Field for number words If vDecimal = 0 And vDollar = 0 And vStrLeft <> "000000" Then Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " + vStrLeft + " \* CardText", _ PreserveFormatting:=True 'Removed *\ Caps to use lowercase End If
'If percent, but not dollar, insert word "Percent" If vPercent <> 0 And vDollar = 0 Then vClearSpace = ClearExtraSpace() 'Deletes extra space in "millions" Selection.TypeText Text:=" percent" End If
'If dollar, insert Fields for left/right numbers w/decimal point and "Dollars" If vDollar <> 0 Then vStrRightLen = Len(vStrRight) 'Ensures decimal has only two digits If vStrRightLen > 2 Then vStrRight = Mid(vStrRight, 1, 2) 'Strips excess digits End If 'If left of decimal = 0, and right is no 00, insert "No Dollars" If vStrLeft = "0" Then Selection.TypeText Text:="No Dollars" Else If vStrLeft = "1" Then 'If left of decimal = 1, insert "One Dollar" Selection.TypeText Text:="One Dollar" Else 'Else insert the "dollars" using "CardText" If vStrLeft <> "000000" Then Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " + vStrLeft + " \* CardText \* Caps", _ PreserveFormatting:=True Selection.TypeText Text:=" " End If Selection.TypeText Text:="Dollars" 'Insert words after numbers End If End If If vStrRight <> "00" Then 'If right of the decimal is not 00, insert cents Selection.TypeText Text:=" and " 'Insert "and" before decimal numbers Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " + vStrRight + " \* CardText \* Caps", _ PreserveFormatting:=True If vStrRight = "01" Then Selection.TypeText Text:=" Cent" 'Insert "Cent" for "One Cent" Else Selection.TypeText Text:=" Cents" 'Insert "Cents" for other "cents" End If Else Selection.TypeText Text:=" and No Cents" 'Insert "No Cents" if 0 cents End If End If
vClearSpace = ClearExtraSpace() 'Deletes extra space in "millions" Selection.TypeText Text:=" (" 'Type parenthesis and actual number into doc If vMinus <> 0 Then Selection.TypeText Text:="-" 'Add minus symbol If vDollar <> 0 Then Selection.TypeText Text:="$" 'Add dollar symbol 'Type billions and millions followed by comma If vStrLeftBil <> "" Then Selection.TypeText Text:=vStrLeftBil + "," If vStrLeftMil <> "" Then Selection.TypeText Text:=vStrLeftMil + "," If vStrLeftLen > 3 Then 'Insert hundred thousands with comma vStrLeftThou = Mid(vStrLeft, 1, vStrLeftLen - 3) vStrLeft = Mid(vStrLeft, vStrLeftLen - 2, 3) Selection.TypeText Text:=vStrLeftThou + "," End If Selection.TypeText Text:=vStrLeft 'Insert remaining hundreds 'Add decimal point if vDecimal or vDollar is true If vDecimal <> 0 Or vDollar <> 0 Then Selection.TypeText Text:="." Selection.TypeText Text:=vStrRight 'Insert right side string 'Remove trailing 0 if vDecimal is 0 (assigned in first routine above 'to assign vStrLeft & vStrRight If vDecimal = 0 And vStrRight = "0" Then Selection.TypeBackspace If vPercent <> 0 Then Selection.TypeText Text:="%" 'Add percent symbol Selection.TypeText Text:=")" 'Insert closing parenthesis
GoTo SkipErrorMsg 'Jumps over GreatThanBillion error message
GreaterThanBillion: 'GreaterThanBillion error message ret = MsgBox("Number is Greater than 999,999,999,999.99!" + vbCr + _ "Macro will now terminate.", vbOKOnly + vbExclamation, "NumConv Macro Error!")
SkipErrorMsg: 'Ends macro
End Sub Function ClearExtraSpace() 'Deletes extra space when "million " used in some cases If Selection.Characters.First.Previous = " " Then Selection.TypeBackspace End If End Function
Jean-Guy Marcil - 22 Feb 2005 16:42 GMT prkhan56 was telling us: prkhan56 nous racontait que :
> Sorry... I missed it.. I am posting it here Try this slightly modified version. Just replace the constant values by what you need in the lines Const CurSym As String = "$" Const MainCurName As String = "Dollar" Const MinorCurSym As String = "Cent"
For the changes in text order and using () or not, you have to modify the macro starting at: 'Deletes extra space in "millions" vClearSpace = ClearExtraSpace() 'Type parenthesis and actual number into doc etc.
'_______________________________________ Sub ConvertDigitToText()
Dim vOrigNum As String Dim vOrigNumPercent As String Dim vDollar As Integer Dim vPercent As Integer Dim vDecimal As Integer Dim vStrLeft As String Dim vStrLeftLen As Integer Dim vStrRight As String Dim vStrRightLen As Integer Dim vStrChar As String Dim vStrHoldStr As String Dim vStrHoldStrLen As Integer Dim vStrLeftMil As String Dim vStrLeftBil As String Dim vStrLeftThou As String Dim vSrrLeftHun As String Dim vClearSpace As String
Const CurSym As String = "$" Const MainCurName As String = "Dollar" Const MinorCurSym As String = "Cent"
'Assigns selection to variable vOrigNum = Trim(Selection.Text)
'Sets length of selected number to Variable vOrigNumLen = Len(vOrigNum) 'Checks to see if number is dollar figure vDollar = InStr(1, vOrigNum, CurSym) 'Checks to see if number is a percent vPercent = InStr(1, vOrigNum, "%") 'Checks to see if number is negative vMinus = InStr(1, vOrigNum, "-")
If vMinus <> 0 Then 'If a dollar amount, then Caps; otherwise, lowercase If vDollar <> 0 Then 'Types Minus if no. is negative Selection.TypeText Text:="Minus " Else 'Types minus if no. is negative Selection.TypeText Text:="minus " End If End If
'Strips all but numbers from variable For i = 1 To vOrigNumLen vStrChar = Mid$(vOrigNum, i, 1) Select Case vStrChar Case ",", CurSym, "%", "-", "I", "R", "S" Case Else 'Stripped number assigned to new variable vStrHoldStr = vStrHoldStr & vStrChar End Select Next i
'Checks length of stripped number vStrHoldStrLen = Len(vStrHoldStr)
'Checks to see if number includes decimal vDecimal = InStr(1, vStrHoldStr, ".")
'If number includes decimal, 'assigns zeros if needed to the left or Right If vDecimal <> 0 Then vStrLeft = Mid(vStrHoldStr, 1, vDecimal - 1) If vStrLeft = "" Then 'Adds left zero for ".87" type number vStrLeft = "0" End If If vStrHoldStrLen - vDecimal = "0" Then 'Adds right zero for "87." type number vStrRight = "0" 'Adds two zeros for "$87." type number If vDollar <> 0 Then vStrRight = "00" Else 'Assigns actual numbers to vStrRight if they exist vStrRight = Mid(vStrHoldStr, vDecimal + 1, _ vStrHoldStrLen - vDecimal) End If End If
'If there is no decimal, assigns number to vStrLeft If vDecimal = 0 Then vStrLeft = vStrHoldStr 'and adds 0 or 00, as appropriate, to vStrRight vStrRight = "0" If vDollar <> 0 Then vStrRight = "00" End If
'Assigns length of vStrLeft to vStrLeftLen vStrLeftLen = Len(vStrLeft)
'If > billion, exit If vStrLeftLen > 12 Then GoTo GreaterThanBillion
'If billions, strip billions string and 'insert into doc using Field If vStrLeftLen > 9 Then 'Start at position 1, move right Length - 9 positions vStrLeftBil = Mid(vStrLeft, 1, vStrLeftLen - 9) 'Assign leftover string to vStrLeft, start 'at Length-8, move 9 positions vStrLeft = Mid(vStrLeft, vStrLeftLen - 8, 9) vStrLeftLen = Len(vStrLeft) 'If a dollar amount, then Caps; otherwise, lowercase If vDollar <> 0 Then Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftBil & " \* CardText \* Caps", _ PreserveFormatting:=True Selection.TypeText Text:=" Billion " Else Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftBil & " \* CardText", _ PreserveFormatting:=True Selection.TypeText Text:=" billion " End If Else 'If no billions, check millions GoTo CheckMillions End If
CheckMillions: 'If millions, strip millions string and insert into doc using Field If vStrLeftLen > 6 Then 'Start at position 1, move right Length - 6 positions vStrLeftMil = Mid(vStrLeft, 1, vStrLeftLen - 6) 'Assign leftover string to vStrLeft, 'start Length-5, move 6 positions vStrLeft = Mid(vStrLeft, vStrLeftLen - 5, 6) vStrLeftLen = Len(vStrLeft) 'If there is no millions, go to thousands If vStrLeftMil = "000" Then GoTo DoThousands End If 'If a dollar amount, then Caps; otherwise, lowercase If vDollar <> 0 Then Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftMil & " \* CardText \* Caps ", _ PreserveFormatting:=True Selection.TypeText Text:=" Million " Else Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftMil & " \* CardText ", _ PreserveFormatting:=True Selection.TypeText Text:=" million " End If Else 'If no millions, do hundred thousands GoTo DoThousands End If
DoThousands: 'If decimal, but not dollar, insert thousands, but skip if 0 If vDecimal <> 0 And vDollar = 0 And vStrLeft <> "000000" Then 'Removed \* Caps to use lowercase Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeft & " \* CardText", _ PreserveFormatting:=True End If 'If decimal, but not dollar, insert left/right Fields using "point" If vDecimal <> 0 And vDollar = 0 Then 'Deletes extra space in "millions" vClearSpace = ClearExtraSpace() Selection.TypeText " point " vStrRightLen = Len(vStrRight) 'Individually insert each right side Number For i = 1 To vStrRightLen 'Removed \* Caps to use lowercase Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & Mid(vStrRight, i, 1) & " \* CardText", _ PreserveFormatting:=True Selection.TypeText Text:=" " Next i Selection.TypeBackspace End If
'If not decimal, and not dollar, just insert Field for number words If vDecimal = 0 And vDollar = 0 And vStrLeft <> "000000" Then 'Removed \* Caps to use lowercase Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeft & " \* CardText", _ PreserveFormatting:=True End If
'If percent, but not dollar, insert word "Percent" If vPercent <> 0 And vDollar = 0 Then 'Deletes extra space in "millions" vClearSpace = ClearExtraSpace() Selection.TypeText Text:=" percent" End If
'If dollar, insert Fields for left/right numbers 'w/decimal point and "Dollars" If vDollar <> 0 Then 'Ensures decimal has only two digits vStrRightLen = Len(vStrRight) If vStrRightLen > 2 Then 'Strips excess digits vStrRight = Mid(vStrRight, 1, 2) End If 'If left of decimal = 0, and right is no 00, insert "No Dollars "" If vStrLeft = "0" Then Selection.TypeText Text:="No " & MainCurName & "s" Else 'If left of decimal = 1, insert "One Dollar" If vStrLeft = "1" Then Selection.TypeText Text:="One " & MainCurName 'Else insert the "dollars" using "CardText" Else If vStrLeft <> "000000" Then Selection.Fields.Add Range:=Selection.Range, _ Type:=wdFieldEmpty, _ Text:="= " & vStrLeft & " \* CardText \* Caps", _ PreserveFormatting:=True Selection.TypeText Text:=" " End If 'Insert words after numbers Selection.TypeText Text:=MainCurName & "s" End If End If 'If right of the decimal is not 00, Insert Cents If vStrRight <> "00" Then 'Insert "and" before decimal numbers Selection.TypeText Text:=" and " Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrRight & " \* CardText \* Caps", _ PreserveFormatting:=True If vStrRight = "01" Then 'Insert "Cent" for "One Cent" Selection.TypeText Text:=" " & MinorCurSym Else 'Insert "Cents" for other "cents" Selection.TypeText Text:=" " & MinorCurSym & "s" End If Else 'Insert "No Cents " if 0 cents" Selection.TypeText Text:=" and No " & MinorCurSym & "s" End If End If
'Deletes extra space in "millions" vClearSpace = ClearExtraSpace() 'Type parenthesis and actual number into doc Selection.TypeText Text:=" (" 'Add minus symbol If vMinus <> 0 Then Selection.TypeText Text:="-" 'Add dollar symbol If vDollar <> 0 Then Selection.TypeText Text:=CurSym 'Type billions and millions followed by comma If vStrLeftBil <> "" Then Selection.TypeText Text:=vStrLeftBil & "," If vStrLeftMil <> "" Then Selection.TypeText Text:=vStrLeftMil & "," 'Insert hundred thousands with comma If vStrLeftLen > 3 Then vStrLeftThou = Mid(vStrLeft, 1, vStrLeftLen - 3) vStrLeft = Mid(vStrLeft, vStrLeftLen - 2, 3) Selection.TypeText Text:=vStrLeftThou & "," End If 'Insert remaining hundreds Selection.TypeText Text:=vStrLeft 'Add decimal point if vDecimal or vDollar is true If vDecimal <> 0 Or vDollar <> 0 Then Selection.TypeText Text:="." 'Insert right side string Selection.TypeText Text:=vStrRight 'Remove trailing 0 if vDecimal is 0 (assigned in first routine above 'to assign vStrLeft & vStrRight If vDecimal = 0 And vStrRight = "0" Then Selection.TypeBackspace 'Add percent symbol If vPercent <> 0 Then Selection.TypeText Text:="%" 'Insert closing parenthesis Selection.TypeText Text:=")"
'Jumps over GreatThanBillion error message Exit Sub
'GreaterThanBillion error message GreaterThanBillion: MsgBox "Number is Greater than 999,999,999,999.99!" & vbCr & _ "Macro will now terminate.", vbExclamation, "Invalid Number"
End Sub '_______________________________________
'_______________________________________ Function ClearExtraSpace()
'Deletes extra space when "million " used in some cases If Selection.Characters.First.Previous = " " Then Selection.TypeBackspace End If
End Function '_______________________________________
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
prkhan56 - 23 Feb 2005 08:49 GMT Hi Jean, Thanks but it gives an error.. "Unexpected End of Formula"
I just changed the following as suggested
quote..... Just replace the constant values by what you need in the lines Const CurSym As String = "$" Const MainCurName As String = "Dollar" Const MinorCurSym As String = "Cent" .....unquote
I am a newbie and therefore could not get the following suggestions by you
quote.... For the changes in text order and using () or not, you have to modify the macro starting at: 'Deletes extra space in "millions" vClearSpace = ClearExtraSpace() ... unquote
Can you please further have a look at the macro given below
Sub ConvertDigitToText() Dim vOrigNum As String Dim vOrigNumPercent As String Dim vDollar As Integer Dim vPercent As Integer Dim vDecimal As Integer Dim vStrLeft As String Dim vStrLeftLen As Integer Dim vStrRight As String Dim vStrRightLen As Integer Dim vStrChar As String Dim vStrHoldStr As String Dim vStrHoldStrLen As Integer Dim vStrLeftMil As String Dim vStrLeftBil As String Dim vStrLeftThou As String Dim vSrrLeftHun As String Dim vClearSpace As String Const CurSym As String = "IRS" Const MainCurName As String = "Rupees" Const MinorCurSym As String = "Paise" 'Assigns selection to variable vOrigNum = Trim(Selection.Text) 'Sets length of selected number to Variable vOrigNumLen = Len(vOrigNum) 'Checks to see if number is dollar figure vDollar = InStr(1, vOrigNum, CurSym) 'Checks to see if number is a percent vPercent = InStr(1, vOrigNum, "%") 'Checks to see if number is negative vMinus = InStr(1, vOrigNum, "-") If vMinus <> 0 Then 'If a dollar amount, then Caps; otherwise, lowercase If vDollar <> 0 Then 'Types Minus if no. is negative Selection.TypeText Text:="Minus " Else 'Types minus if no. is negative Selection.TypeText Text:="minus " End If End If 'Strips all but numbers from variable For i = 1 To vOrigNumLen vStrChar = Mid$(vOrigNum, i, 1) Select Case vStrChar Case ",", CurSym, "%", "-", "I", "R", "S" Case Else 'Stripped number assigned to new variable vStrHoldStr = vStrHoldStr & vStrChar End Select Next i 'Checks length of stripped number vStrHoldStrLen = Len(vStrHoldStr) 'Checks to see if number includes decimal vDecimal = InStr(1, vStrHoldStr, ".") 'If number includes decimal, 'assigns zeros if needed to the left or Right If vDecimal <> 0 Then vStrLeft = Mid(vStrHoldStr, 1, vDecimal - 1) If vStrLeft = "" Then 'Adds left zero for ".87" type number vStrLeft = "0" End If If vStrHoldStrLen - vDecimal = "0" Then 'Adds right zero for "87." type number vStrRight = "0" 'Adds two zeros for "$87." type number If vDollar <> 0 Then vStrRight = "00" Else 'Assigns actual numbers to vStrRight if they exist vStrRight = Mid(vStrHoldStr, vDecimal + 1, _ vStrHoldStrLen - vDecimal) End If End If 'If there is no decimal, assigns number to vStrLeft If vDecimal = 0 Then vStrLeft = vStrHoldStr 'and adds 0 or 00, as appropriate, to vStrRight vStrRight = "0" If vDollar <> 0 Then vStrRight = "00" End If 'Assigns length of vStrLeft to vStrLeftLen vStrLeftLen = Len(vStrLeft) 'If > billion, exit If vStrLeftLen > 12 Then GoTo GreaterThanBillion 'If billions, strip billions string and 'insert into doc using Field If vStrLeftLen > 9 Then 'Start at position 1, move right Length - 9 positions vStrLeftBil = Mid(vStrLeft, 1, vStrLeftLen - 9) 'Assign leftover string to vStrLeft, start 'at Length-8, move 9 positions vStrLeft = Mid(vStrLeft, vStrLeftLen - 8, 9) vStrLeftLen = Len(vStrLeft) 'If a dollar amount, then Caps; otherwise, lowercase If vDollar <> 0 Then Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftBil & " \* CardText \* Caps", _ PreserveFormatting:=True Selection.TypeText Text:=" Billion " Else Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftBil & " \* CardText", _ PreserveFormatting:=True Selection.TypeText Text:=" billion " End If Else 'If no billions, check millions GoTo CheckMillions End If CheckMillions: 'If millions, strip millions string and insert into doc using Field If vStrLeftLen > 6 Then 'Start at position 1, move right Length - 6 positions vStrLeftMil = Mid(vStrLeft, 1, vStrLeftLen - 6) 'Assign leftover string to vStrLeft, 'start Length-5, move 6 positions vStrLeft = Mid(vStrLeft, vStrLeftLen - 5, 6) vStrLeftLen = Len(vStrLeft) 'If there is no millions, go to thousands If vStrLeftMil = "000" Then GoTo DoThousands End If 'If a dollar amount, then Caps; otherwise, lowercase If vDollar <> 0 Then Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftMil & " \* CardText \* Caps ", _ PreserveFormatting:=True Selection.TypeText Text:=" Million " Else Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftMil & " \* CardText ", _ PreserveFormatting:=True Selection.TypeText Text:=" million " End If Else 'If no millions, do hundred thousands GoTo DoThousands End If DoThousands: 'If decimal, but not dollar, insert thousands, but skip if 0 If vDecimal <> 0 And vDollar = 0 And vStrLeft <> "000000" Then 'Removed \* Caps to use lowercase Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeft & " \* CardText", _ PreserveFormatting:=True End If 'If decimal, but not dollar, insert left/right Fields using "point" If vDecimal <> 0 And vDollar = 0 Then 'Deletes extra space in "millions" vClearSpace = ClearExtraSpace() Selection.TypeText " point " vStrRightLen = Len(vStrRight) 'Individually insert each right side Number For i = 1 To vStrRightLen 'Removed \* Caps to use lowercase Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & Mid(vStrRight, i, 1) & " \* CardText", _ PreserveFormatting:=True Selection.TypeText Text:=" " Next i Selection.TypeBackspace End If 'If not decimal, and not dollar, just insert Field for number words If vDecimal = 0 And vDollar = 0 And vStrLeft <> "000000" Then 'Removed \* Caps to use lowercase Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeft & " \* CardText", _ PreserveFormatting:=True End If 'If percent, but not dollar, insert word "Percent" If vPercent <> 0 And vDollar = 0 Then 'Deletes extra space in "millions" vClearSpace = ClearExtraSpace() Selection.TypeText Text:=" percent" End If 'If dollar, insert Fields for left/right numbers 'w/decimal point and "Dollars" If vDollar <> 0 Then 'Ensures decimal has only two digits vStrRightLen = Len(vStrRight) If vStrRightLen > 2 Then 'Strips excess digits vStrRight = Mid(vStrRight, 1, 2) End If 'If left of decimal = 0, and right is no 00, insert "No Dollars "" If vStrLeft = "0" Then Selection.TypeText Text:="No " & MainCurName & "s" Else 'If left of decimal = 1, insert "One Dollar" If vStrLeft = "1" Then Selection.TypeText Text:="One " & MainCurName 'Else insert the "dollars" using "CardText" Else If vStrLeft <> "000000" Then Selection.Fields.Add Range:=Selection.Range, _ Type:=wdFieldEmpty, _ Text:="= " & vStrLeft & " \* CardText \* Caps", _ PreserveFormatting:=True Selection.TypeText Text:=" " End If 'Insert words after numbers Selection.TypeText Text:=MainCurName & "s" End If End If 'If right of the decimal is not 00, Insert Cents If vStrRight <> "00" Then 'Insert "and" before decimal numbers Selection.TypeText Text:=" and " Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrRight & " \* CardText \* Caps", _ PreserveFormatting:=True If vStrRight = "01" Then 'Insert "Cent" for "One Cent" Selection.TypeText Text:=" " & MinorCurSym Else 'Insert "Cents" for other "cents" Selection.TypeText Text:=" " & MinorCurSym & "s" End If Else 'Insert "No Cents " if 0 cents" Selection.TypeText Text:=" and No " & MinorCurSym & "s" End If End If 'Deletes extra space in "millions" vClearSpace = ClearExtraSpace() 'Type parenthesis and actual number into doc Selection.TypeText Text:=" (" 'Add minus symbol If vMinus <> 0 Then Selection.TypeText Text:="-" 'Add dollar symbol If vDollar <> 0 Then Selection.TypeText Text:=CurSym 'Type billions and millions followed by comma If vStrLeftBil <> "" Then Selection.TypeText Text:=vStrLeftBil & "," If vStrLeftMil <> "" Then Selection.TypeText Text:=vStrLeftMil & "," 'Insert hundred thousands with comma If vStrLeftLen > 3 Then vStrLeftThou = Mid(vStrLeft, 1, vStrLeftLen - 3) vStrLeft = Mid(vStrLeft, vStrLeftLen - 2, 3) Selection.TypeText Text:=vStrLeftThou & "," End If 'Insert remaining hundreds Selection.TypeText Text:=vStrLeft 'Add decimal point if vDecimal or vDollar is true If vDecimal <> 0 Or vDollar <> 0 Then Selection.TypeText Text:="." 'Insert right side string Selection.TypeText Text:=vStrRight 'Remove trailing 0 if vDecimal is 0 (assigned in first routine above 'to assign vStrLeft & vStrRight If vDecimal = 0 And vStrRight = "0" Then Selection.TypeBackspace 'Add percent symbol If vPercent <> 0 Then Selection.TypeText Text:="%" 'Insert closing parenthesis Selection.TypeText Text:=")" 'Jumps over GreatThanBillion error message Exit Sub 'GreaterThanBillion error message GreaterThanBillion: MsgBox "Number is Greater than 999,999,999,999.99!" & vbCr & _ "Macro will now terminate.", vbExclamation, "Invalid Number" End Sub '_______________________________________ '_______________________________________ Function ClearExtraSpace() 'Deletes extra space when "million " used in some cases If Selection.Characters.First.Previous = " " Then Selection.TypeBackspace End If End Function
Thanks for your time and help
Rashid
Jean-Guy Marcil - 23 Feb 2005 14:06 GMT prkhan56 was telling us: prkhan56 nous racontait que :
> Hi Jean, > Thanks but it gives an error.. "Unexpected End of Formula" [quoted text clipped - 7 lines] > Const MinorCurSym As String = "Cent" > .....unquote Which line of code gave you an error (Hit Debug when the error is thrown and you will be taken to a highlighted line of code) Also, I think I neglected to mention that I changed one aspect of the macro. Because of your IRS (which is in fact three characters, not one like the $) you now have to select the whole number (From IRS to the last digit, not including the spaces around it). Finally, does Rupees always takes an "s"? IF not, remove it from the constant definition,. If so, you will have to modify the code where the word Rupees is inserted, otherwise you will have Rupeess. Look for the lines containing MainCurName (In the VBE window you can use Edit > Find...)
> I am a newbie and therefore could not get the following suggestions by > you Each line of code that contains Selection.TypeText Text:=Something is a line of text that potentially types text in the document (Potentially because of the presence of "If" in some cases). Put a stop on the first line that has a Selection.TypeText Text (Click on the grey border to the left of the code, a big red dot will appear on the border next to the line of code, this means that the code execution will stop just before executing this line, this is a break.) When the code breaks on that line, reduce the VBE window so that it allows you to see what is going on in the document, I like to make the VBE window occupy half the screen (horizontally). Then hit F8, the code will execute line by line, this way you will see what each line does on the document (Position the document so as to see what is going on, you can go to the document window to scroll it before going back to the VBE window). Do that a few time to get familiar with the code, also, do it with large numbers because some part of the code only get executed with large numbers. When you are more familiar with the code, either change the content of the text between quotes in the lines Selection.TypeText Text:="-" to reflect what you want, or move them around to change the order. If there are If statements, move the whole If block (From If... to ... End If).
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
prkhan56 - 01 Mar 2005 14:35 GMT Hello Jean, Sorry my system was down so could not get back to u. The following are the output and errors it gives .. Please check and help me out
Items 2, 3, 5 and 8 are ok .. Item 4 and 6 gives unexpected end of formula..
1) One Hundred Rupees and No Paise IRS ,100.00 -> ERROR FOR 100.00 PRINTS ,100.00
2) One Thousand Two Hundred Thirty-Four Rupees and No Paise IRS 1,234.00 -> OK
3) Twelve Thousand Three Hundred Forty-Five Rupees and Sixty Paise IRS 12,345.60 -> OK
4) Million One Hundred Twenty-Three Thousand Three Hundred Forty-Five Rupees and Seventy-Eight Paise IRS ,123,345.78 !Unexpected End of Formula -> ERROR
5) One Million Two Hundred Thirty-Four Thousand Five Hundred Sixty-Seven Rupees and Ninety Paise IRS 1,234,567.90 -> OK
6) Billion One Hundred Two Million Two Hundred Thirty-Four Thousand Five Hundred Sixty-Seven Rupees and Ninety Paise IRS ,102,234,567.90 !Unexpected End of Formula -> ERROR
7) Ten Rupees and No Paise IRS 10.00 -> OK
8) One Rupees and No Paise IRS 1.00 -> OK
9) Twenty-Five Rupees and No Paise IRS ,25 .00 -> ERROR .. 00 PRINTS ON THE NEXT LINE
Thanks for your time and help Rashid
Jean-Guy Marcil - 01 Mar 2005 14:54 GMT prkhan56 was telling us: prkhan56 nous racontait que :
> Hello Jean, > Sorry my system was down so could not get back to u. The following > are the output and errors it gives .. Please check and help me out You posted the results, but not what you started with.... I think there is something inconsistent in the way your numbers are written on the document.
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
prkhan56 - 02 Mar 2005 06:18 GMT Hello Jean, The numbers I written on the document are just before the ( -> ) symbol.. I posted the whole result..
I write the numbers as IRS 1,234.50 then select it and run your macro.. then the results come which I have posted
Thanks for your time and help Rashid
Jean-Guy Marcil - 02 Mar 2005 08:43 GMT prkhan56 was telling us: prkhan56 nous racontait que :
> Hello Jean, > The numbers I written on the document are just before the ( -> ) > symbol.. You posted things like: <quote> 1) One Hundred Rupees and No Paise IRS ,100.00 -> ERROR FOR 100.00 PRINTS ,100.00 <unquote>
This means that you stated with numbers like "IRS ,100.00" I do not think so. This is why I asked you to post the actual numbers you started with.
> I posted the whole result.. > > I write the numbers as IRS 1,234.50 then select it and run your > macro.. then the results come which I have posted I see the problem. In the original post, you wrote
<quote> $1,234.50 - converts to One Thousand Two Hundred Thirty Four Dollars and Fifty Cents ($1,234.50)
I wish to change - the $ to IRS (our local currency) <unquote>
So I just replaces the $ by IRS. But it seems the space between the IRS and the first digit is important. Small detail that is actually quite important.
So, I believe that it you change
Const CurSym As String = "$" to Const CurSym As String = "IRS " (with a space)
and
Case ",", CurSym, "%", "-", "I", "R", "S" to Case ",", CurSym, "%", "-", "I", "R", "S", " "
to eliminate the space from the number itself, then it should work OK. It did on my machine with the numbers you posted as problematic.
Also, is "Rupees" always plural? If so, adjust the macro to eliminate the insertion on an "s". Otherwise you will end up with "Rupeess". How about "Paise"?
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
prkhan56 - 03 Mar 2005 04:35 GMT I would try and come back Thanks
prkhan56 - 07 Mar 2005 09:06 GMT Hello Jean, Further to your mail. 1) Please note that Rupee is singular and Rupees is plural. If the value is 1 then it should show as One Rupee and if more than 1 then it should show as Rupees. 2) Paise is a plural term. 3) There is always a space between IRS and the number eg. IRS 12,345.67
Please find below the results given by the macro:
Eg. IRS 12,345 (without decimal) - this displays as Twelve Thousand Three Hundred Forty-Five Dirhams and No Fils IRS 123,45 .00
Note that the comma (,) is shifted after the third digit and the decimal (.00) jumps to the next line
If no Currency Symbol is defined Eg. 12,345.60 - this displays as twelve thousand three hundred forty-five point six12,345.60 !Unexpected End of Formula
I wish to have it in the following format IRS 12,345.60 - should display as IRS 12,345.60 Twelve Thousand Three Hundred Forty-Five and Sixty Paise only The symbol and digit should come before the word
Rest all the values work fine.
I really appreciate your time and help in this matter.
Thank you once again Rashid
Jean-Guy Marcil - 07 Mar 2005 15:54 GMT prkhan56 was telling us: prkhan56 nous racontait que :
> Hello Jean, > Further to your mail. [quoted text clipped - 11 lines] > and No Fils IRS 123,45 > .00 IRS 12,345 worked as expected on my mahine, no problems.
> Note that the comma (,) is shifted after the third digit and the > decimal (.00) jumps to the next line > > If no Currency Symbol is defined > Eg. 12,345.60 - this displays as twelve thousand three hundred > forty-five point six12,345.60 !Unexpected End of Formula This number also worked as expected.
> I wish to have it in the following format > IRS 12,345.60 - should display as [quoted text clipped - 5 lines] > > I really appreciate your time and help in this matter. Here is a simplified macro. It does not look at negative/percent numbers because all you seem interested in is getting the currently selected currency amount in writing, with a few checks for inconsistencies regarding decimal values. If there is not IRS in the selection, then the number gets a regular number treatment, not a currency treatment. Again, on my machine all tests were positive if I selected things like:
IRS 12,345 IRS 12,345.56 IRS 1,512,345.23 12,345 12,345.23
'_______________________________________ Sub ConvertDigitToText()
Dim vOrigNum As String Dim vOrigNumPercent As String Dim vDollar As Integer Dim vDecimal As Integer Dim vStrLeft As String Dim vStrLeftLen As Integer Dim vStrRight As String Dim vStrRightLen As Integer Dim vStrChar As String Dim vStrHoldStr As String Dim vStrHoldStrLen As Integer Dim vStrLeftMil As String Dim vStrLeftBil As String Dim vStrLeftThou As String Dim vSrrLeftHun As String Dim vClearSpace As String
Const CurSym As String = "IRS " Const MainCurName As String = "Rupee" Const MinorCurSym As String = "Paise"
'Assigns selection to variable vOrigNum = Trim(Selection.Text)
'Sets length of selected number to Variable vOrigNumLen = Len(vOrigNum) 'Checks to see if number is dollar figure vDollar = InStr(1, vOrigNum, CurSym)
'Strips all but numbers from variable For i = 1 To vOrigNumLen vStrChar = Mid$(vOrigNum, i, 1) Select Case vStrChar Case ",", CurSym, "%", "-", "I", "R", "S", " " Case Else 'Stripped number assigned to new variable vStrHoldStr = vStrHoldStr & vStrChar End Select Next i
'Checks length of stripped number vStrHoldStrLen = Len(vStrHoldStr)
'Checks to see if number includes decimal vDecimal = InStr(1, vStrHoldStr, ".")
'If number includes decimal, 'assigns zeros if needed to the left or Right If vDecimal <> 0 Then vStrLeft = Mid(vStrHoldStr, 1, vDecimal - 1) If vStrLeft = "" Then 'Adds left zero for ".87" type number vStrLeft = "0" End If If vStrHoldStrLen - vDecimal = "0" Then 'Adds right zero for "87." type number vStrRight = "0" 'Adds two zeros for "$87." type number If vDollar <> 0 Then vStrRight = "00" Else 'Assigns actual numbers to vStrRight if they exist vStrRight = Mid(vStrHoldStr, vDecimal + 1, _ vStrHoldStrLen - vDecimal) End If End If
'If there is no decimal, assigns number to vStrLeft If vDecimal = 0 Then vStrLeft = vStrHoldStr 'and adds 0 or 00, as appropriate, to vStrRight vStrRight = "0" If vDollar <> 0 Then vStrRight = "00" End If
'Assigns length of vStrLeft to vStrLeftLen vStrLeftLen = Len(vStrLeft)
Selection.Collapse wdCollapseEnd Selection.TypeText Text:=" "
'If > billion, exit If vStrLeftLen > 12 Then GoTo GreaterThanBillion
'If billions, strip billions string and 'insert into doc using Field If vStrLeftLen > 9 Then 'Start at position 1, move right Length - 9 positions vStrLeftBil = Mid(vStrLeft, 1, vStrLeftLen - 9) 'Assign leftover string to vStrLeft, start 'at Length-8, move 9 positions vStrLeft = Mid(vStrLeft, vStrLeftLen - 8, 9) vStrLeftLen = Len(vStrLeft) 'If a dollar amount, then Caps; otherwise, lowercase If vDollar <> 0 Then Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftBil & " \* CardText \* Caps", _ PreserveFormatting:=True Selection.TypeText Text:=" Billion " Else Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftBil & " \* CardText", _ PreserveFormatting:=True Selection.TypeText Text:=" billion " End If Else 'If no billions, check millions GoTo CheckMillions End If
CheckMillions: 'If millions, strip millions string and insert into doc using Field If vStrLeftLen > 6 Then 'Start at position 1, move right Length - 6 positions vStrLeftMil = Mid(vStrLeft, 1, vStrLeftLen - 6) 'Assign leftover string to vStrLeft, 'start Length-5, move 6 positions vStrLeft = Mid(vStrLeft, vStrLeftLen - 5, 6) vStrLeftLen = Len(vStrLeft) 'If there is no millions, go to thousands If vStrLeftMil = "000" Then GoTo DoThousands End If 'If a dollar amount, then Caps; otherwise, lowercase If vDollar <> 0 Then Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftMil & " \* CardText \* Caps ", _ PreserveFormatting:=True Selection.TypeText Text:=" Million " Else Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeftMil & " \* CardText ", _ PreserveFormatting:=True Selection.TypeText Text:=" million " End If Else 'If no millions, do hundred thousands GoTo DoThousands End If
DoThousands: 'If decimal, but not dollar, insert thousands, but skip if 0 If vDecimal <> 0 And vDollar = 0 And vStrLeft <> "000000" Then 'Removed \* Caps to use lowercase Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeft & " \* CardText", _ PreserveFormatting:=True End If 'If decimal, but not dollar, insert left/right Fields using "point" If vDecimal <> 0 And vDollar = 0 Then 'Deletes extra space in "millions" vClearSpace = ClearExtraSpace() Selection.TypeText " point " vStrRightLen = Len(vStrRight) 'Individually insert each right side Number For i = 1 To vStrRightLen 'Removed \* Caps to use lowercase Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & Mid(vStrRight, i, 1) & " \* CardText", _ PreserveFormatting:=True Selection.TypeText Text:=" " Next i Selection.TypeBackspace End If
'If not decimal, and not dollar, just insert Field for number words If vDecimal = 0 And vDollar = 0 And vStrLeft <> "000000" Then 'Removed \* Caps to use lowercase Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrLeft & " \* CardText", _ PreserveFormatting:=True End If
'If dollar, insert Fields for left/right numbers 'w/decimal point and "Dollars" If vDollar <> 0 Then 'Ensures decimal has only two digits vStrRightLen = Len(vStrRight) If vStrRightLen > 2 Then 'Strips excess digits vStrRight = Mid(vStrRight, 1, 2) End If 'If left of decimal = 0, and right is no 00, insert "No Dollars "" If vStrLeft = "0" Then Selection.TypeText Text:="No " & MainCurName & "s" Else 'If left of decimal = 1, insert "One Dollar" If vStrLeft = "1" Then Selection.TypeText Text:="One " & MainCurName 'Else insert the "dollars" using "CardText" Else If vStrLeft <> "000000" Then Selection.Fields.Add Range:=Selection.Range, _ Type:=wdFieldEmpty, _ Text:="= " & vStrLeft & " \* CardText \* Caps", _ PreserveFormatting:=True Selection.TypeText Text:=" " End If 'Insert words after numbers Selection.TypeText Text:=MainCurName & "s" End If End If 'If right of the decimal is not 00, Insert Cents If vStrRight <> "00" Then 'Insert "and" before decimal numbers Selection.TypeText Text:=" and " Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _ Text:="= " & vStrRight & " \* CardText \* Caps", _ PreserveFormatting:=True Selection.TypeText Text:=" " & MinorCurSym & "s" Else 'Insert "No Cents " if 0 cents" Selection.TypeText Text:=" and No " & MinorCurSym & "s" End If End If
'Jumps over GreatThanBillion error message Exit Sub
'GreaterThanBillion error message GreaterThanBillion: MsgBox "Number is Greater than 999,999,999,999.99!" & vbCr & _ "Macro will now terminate.", vbExclamation, "Invalid Number"
End Sub '_______________________________________
'_______________________________________ Function ClearExtraSpace()
'Deletes extra space when "million " used in some cases If Selection.Characters.First.Previous = " " Then Selection.TypeBackspace End If
End Function '_______________________________________
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
prkhan56 - 08 Mar 2005 04:54 GMT Ok thanks would revert back if there is some problems
Thanks once again Rashid
prkhan56 - 09 Mar 2005 14:39 GMT Hello Jean, Thank you the macro is working... Please as a last help can you modify it to display as follows
Symbol IRS followed by Text in Words as example shown below:
IRS 1,234.50 One Thousand Two Hundred Thirty-Four and Fifty Paise
One thing I noticed and thought to inform you is that if I select the paragraph mark then the Decimal Jumps to the next line...anyhow that is not a big issue
Please can you help me to display as IRS 1,234.50
I am on the learning curve and just could not get the stuff working without expert help from you.
Thanks a million for all your support and time
Rashid Khan
prkhan56 - 09 Mar 2005 15:10 GMT Hello Jean, Please ignore the post before this..
Sorry by mistake I made the previous post.. The macro works fine with the desired results as IRS followed by text
Thanks again
Rashid Khan
Jean-Guy Marcil - 09 Mar 2005 18:16 GMT prkhan56 was telling us: prkhan56 nous racontait que :
> Hello Jean, > Please ignore the post before this.. [quoted text clipped - 3 lines] > > Thanks again Phew! Had me worried there for a second! Glad it finally worked.
Of course, you are not supposed to select anything but the "IRS (digits)". If you select a ? or a tab or any other special characters, you will get undesirable results.
Cheers.
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
|
|
|