Change date to French

L

Lena

Hey all, depending on what language they chose I want the date to be displayed in French. Why isn't this code working?

If Me.optFrench.Value = True The
Options.MonthNames = wdMonthNamesFrenc
Els
Options.MonthNames = wdMonthNamesEnglis
End I
Me.txtDate.Value = MonthName(Month(Date)) & " " & Day(Date)
& ", " & Year(Date

Thanx in advanced
Lena
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Lena > écrivait :
In this message, < Lena > wrote:

|| Hey all, depending on what language they chose I want the date to be
displayed in French. Why
|| isn't this code working?
||
|| If Me.optFrench.Value = True Then
|| Options.MonthNames = wdMonthNamesFrench
|| Else
|| Options.MonthNames = wdMonthNamesEnglish
|| End If
|| Me.txtDate.Value = MonthName(Month(Date)) & " " & Day(Date) _
|| & ", " & Year(Date)
||

"Options.MonthNames" refers to Word' options, which, I believe, have no
bearing to what is going on in a userform.Also, I believe that "MonthName is
supposed to be used just to return a month format, yet you are using it for
a full date format...

Look up Format in the VBA help... But I do not think that one of the
parameters is "language".

As far as I can tell with my limited knowledge regarding date, is that the
date language is actually controlled by either the system default, which you
do not want to mess with from VBA, unless there is an esay way of doing this
I am unaware of, or Word's dictionary language for a particular range of
text. If you insert a DATE or TIME field and assign French, the date will be
displayed in French, now change the language for that field from French to
English and update the field, you will see the date change language, but not
the format.... You will end up with and English language date with a French
format as in: 12 April 2004.

I have the following "trick" to set the current date's language in a user
form:

'_______________________________________
Private Sub CommandButton1_Click()

Me.Hide
Unload Me

End Sub
'_______________________________________

'_______________________________________
Private Sub optEnglish_Click()

InsertCurDate "MMMM d, yyyy", 4105

End Sub
'_______________________________________

'_______________________________________
Private Sub optFrench_Click()

InsertCurDate "d MMMM yyyy", 3084

End Sub
'_______________________________________

'_______________________________________
Function InsertCurDate(DateForm As String, DateLang As Long)
'1036 = French
'3084 = FrenchCanadian
'4105 = EnglishCanadian
'2057 = EnglishUK

Dim MyRange As Range

Selection.Collapse
Set MyRange = Selection.Range

MyRange.InsertParagraphAfter
MyRange.Collapse
MyRange.InsertParagraphBefore
MyRange.Collapse wdCollapseEnd

MyRange.InsertDateTime DateTimeFormat:=DateForm, InsertAsField:= _
False, DateLanguage:=DateLang, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False
Set MyRange = MyRange.Paragraphs(1).Range
MyRange.MoveEnd wdCharacter, -1

Me.txtDate.Value = MyRange.Text

ActiveDocument.Undo 3

Set MyRange = Nothing

End Function
'_______________________________________

Or you could create an invisible temporary document and dismiss it at the
end, this way you are guaranteed not to mess with the actual document.

Good luck!

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Cabong

a workaround could be to use a Select Case where you would replace th
month in english with the month in French.

Something like:

Function Convert(TheDate)

Select Case TheDate
Case TheDate= "January"
TheDate= "Janvier"
Case TheDate= "February"
TheDate= "Fevrier"

and so on..

assuming there is no other way besides treating it as a string
 
C

Cabong

a workaround could be to use a Select Case where you would replace th
month in english with the month in French.

Something like:

Function Convert(TheDate)

Select Case TheDate
Case TheDate= "January"
TheDate= "Janvier"
Case TheDate= "February"
TheDate= "Fevrier"

and so on..

assuming there is no other way besides treating it as a string
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Cabong > écrivait :
In this message, < Cabong > wrote:

|| a workaround could be to use a Select Case where you would replace the
|| month in english with the month in French.
||
|| Something like:
||

Good idea, except that you still have to convert the syntax... e.g.: April
4, 2004 to 4 avril 2004.
I guess it would be easy enough if you used 3 individual textboxes.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
C

Cabong

I'm not sure if this would work cause I'm not that familiar with wor
but:

I meant that being treated as a string, one would 1st rearrange th
syntax. I think you could isolate the 3 part of the date by looking u
for space in the date string.

e.g. knowing that the month comes 1st, you could "store" all th
letters before you encounter a space, in an array, buy looking up eac
letter in the date string.

You could take the last 4 digit as year , so on and so forth and stor
the month, year, date in 3 seperate arrays.

I know it's a lot of work but I'm sure I could figure it out
 
C

Cabong

I'm not sure if this would work cause I'm not that familiar with wor
but:

I meant that being treated as a string, one would 1st rearrange th
syntax. I think you could isolate the 3 part of the date by looking u
for space in the date string.

e.g. knowing that the month comes 1st, you could "store" all th
letters before you encounter a space, in an array, buy looking up eac
letter in the date string.

You could take the last 4 digit as year , so on and so forth and stor
the month, year, date in 3 seperate arrays.

I know it's a lot of work but I'm sure I could figure it out
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top