Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Heena Nagori   on Jan 16 In MS Office Category.

  
Question Answered By: Varick Fischer   on Jan 16

I don't have an example for Excel. However, I found an example in Access
that should be fairly easy to convert  the method used into Excel. I've also
included some code that I have used in creating Word documents. Hopefully
this will provide some help if no one else has an Excel sample to share.

There is an Access example available at
http://www.mvps.org/access/modules/mdl0047.htm

And this is the code that I use to convert a date to words  in Word.

Insert a string of text at the appropriate bookmark to insert the current
day in Words. Such as On this 21st Day of December, 2002

Sub DayInWords()
'Sub AutoNew()

Dim myDate As Date
Dim varDay As Variant
Dim varMonth As String
Dim varYear As Variant
Dim varSuffix As String
Dim dateAns As String

On Error GoTo EH
myDate = Date

varDay = DatePart("d", myDate)
varMonth = DatePart("m", myDate)
varYear = DatePart("yyyy", myDate)

Select Case varDay
Case 1, 21, 31
varSuffix = "st"
Case 2, 22
varSuffix = "nd"
Case 3, 23
varSuffix = "rd"
Case 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, _
18, 19, 20, 24, 25, 26, 27, 28, 29, 30
varSuffix = "th"
Case Else
MsgBox "Unknown Day"
End Select

Select Case varMonth
Case Is = 1
varMonth = "January"
Case Is = 2
varMonth = "February"
Case Is = 3
varMonth = "March"
Case Is = 4
varMonth = "April"
Case Is = 5
varMonth = "May"
Case Is = 6
varMonth = "June"
Case Is = 7
varMonth = "July"
Case Is = 8
varMonth = "August"
Case Is = 9
varMonth = "September"
Case Is = 10
varMonth = "October"
Case Is = 11
varMonth = "November"
Case Is = 12
varMonth = "December"
Case Else
MsgBox "Month is invalid"
End Select

varDay = varDay & varSuffix
dateAns = varDay & " day of " & varMonth & ", " & varYear
Debug.Print dateAns
'Insert the Date in the appropriate bookmark
Selection.GoTo What:=wdGoToBookmark, Name:="DayInWords"
Selection.InsertBefore dateAns

'Handle Errors Gracefully
Exit_EH:
Exit Sub
EH:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_EH

End Sub

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Conversion of Numerics into Words Or get search suggestion and latest updates.


Tagged: