This is a discussion on How to Create word Macro that converts currency in numbers into words? within the VB.NET Programming forums, part of the Software Development category; How to Create word Macro that converts currency in numbers into words?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Open MSword Click file>close (no more open documents) Click tools>macros>Visual basic editor On the left hand side tree-view, expand 'normal'>'Microsoft word objects' to see 'ThisDocument' Double click on 'ThisDocument' A white (probably blank) window will appear on the right hand side, where you should paste the following code Close all the windows. Installation is complete! Now when you are typing a document, if want to use the converter, Select the number which you want to convert. Press Alt+F8. Press Enter. (check for 'RSconvert' in 'Macro name' text field) This will replace the selected number with its word equivalent Dim arrSingleDigit Dim arrTeen Dim arrTwoDigits Sub RSconvert() On Error Resume Next arrSingleDigit = Array("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten") arrTeen = Array("eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty") arrTwoDigits = Array("10", "twenty ", "thirty ", "forty ", "fifty ", "sixty ", "seventy ", "eighty ", "ninety ", "Hundred") valdig = Trim("" + Selection.Text) If valdig = "" Or IsNumeric(valdig) = False Then Exit Sub valInDigits = valdig paisa = Int(valInDigits * 100 - Int(valInDigits) * 100) valInDigits = Int(valInDigits) If valInDigits > 0 Then If valInDigits > 999999999 Then MsgBox "Beyond Limit" Else msgtmp = convert(valInDigits) + " Rupees" If paisa <> 0 Then msgtmp = msgtmp + " and " + convert(paisa) + " Paisa" msgtmp = UCase(Left(msgtmp, 1)) + Right(msgtmp, Len(msgtmp) - 1) Selection.Text = msgtmp Exit Sub End If End If End Sub Private Function convert(valInDigits) Dim MSB Dim LSB If valInDigits > 0 And valInDigits < 10 Then converted = arrSingleDigit(valInDigits - 1) ElseIf valInDigits = 10 Then converted = "ten" ElseIf ((valInDigits > 10) And (valInDigits < 20)) Then converted = arrTeen(valInDigits Mod 10 - 1) ElseIf ((valInDigits >= 20) And (valInDigits <= 99)) Then MSB = valInDigits \ 10 converted = arrTwoDigits(MSB - 1) LSB = valInDigits Mod 10 If LSB > 0 Then converted = converted + convert(LSB) End If ElseIf ((valInDigits >= 100) And (valInDigits <= 999)) Then MSB = valInDigits \ 100 converted = convert(MSB) + " " + "hundred" LSB = valInDigits Mod 100 If LSB > 0 Then converted = converted + " " + convert(LSB) End If ElseIf ((valInDigits >= 999) And (valInDigits <= 99999)) Then MSB = valInDigits \ 1000 converted = convert(MSB) + " " + "thousand" LSB = valInDigits Mod 1000 If LSB > 0 Then converted = converted + " " + convert(LSB) End If ElseIf ((valInDigits >= 99999) And (valInDigits <= 9999999)) Then MSB = valInDigits \ 100000 converted = convert(MSB) + " " + "lakh" LSB = valInDigits Mod 100000 If LSB > 0 Then converted = converted + " " + convert(LSB) End If ElseIf ((valInDigits >= 9999999) And (valInDigits <= 999999999)) Then MSB = valInDigits \ 10000000 converted = convert(MSB) + " " + "crore" LSB = valInDigits Mod 10000000 If LSB > 0 Then converted = converted + " " + convert(LSB) End If End If convert = converted End Function |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/vb-net-programming/2714-how-create-word-macro-converts-currency-numbers-into-words.html | |||
| Posted By | For | Type | Date |
| How to Create word Macro that converts currency in numbers into words? | Web Hosting | This thread | Refback | 02-26-2008 12:16 PM |
| How to Create word Macro that converts currency in numbers into words? | yourmuses | This thread | Pingback | 10-29-2007 09:16 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Currency format | Kirubhananth | ASP and ASP.NET Programming | 2 | 03-13-2008 03:26 AM |
| what is flapjax and what are its benefits compared to javascript . How it converts fl | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 11-21-2007 02:55 AM |
| SQL reserved words | itbarota | Database Support | 1 | 09-26-2007 09:53 AM |
| Embedded Currency Conversion | Alkazar | HTML, CSS and Javascript Coding Techniques | 1 | 08-27-2007 07:57 AM |
| How to Create an Excel Macro that converts currency in numbers into words? | itbarota | VB.NET Programming | 2 | 08-08-2007 06:23 AM |