Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA - Change date language

I'm trying to solve such problem: In macro, that I'm using, one of the parts is to retrieve date month (in full naming), currently is used :

LastMonth = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "mmmm")

But then one problem appears - for persons, who use different regional language settings, date appears in it's local language, but I need to have it for everyone in English.

I was looking around the internet, but haven't found any similar solutions. Does anyone knows, how can this be solved?

like image 698
Yuriy T. Avatar asked Aug 19 '15 08:08

Yuriy T.


2 Answers

Excel formula TEXT allows defining output language, so one of the options is to use it's VBA equivalent:

LastMonth = WorksheetFunction.Text(Date - Day(Date), "[$-409]mmmm")
like image 169
BrakNicku Avatar answered Nov 03 '22 00:11

BrakNicku


Try this, found it on a forum and it seems to work.

Public Function Format_en(Datum As Date) As String 
Dim DD              As String 
Dim MMM             As String 
Dim YY              As String 

DD = Format(Datum, "dd") 
MMM = Choose(Month(Datum), "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") 
YY = Format(Datum, "yy") 

Format_en = DD & "." & MMM & " " & YY 
End Function 

MsgBox Format_en(Date) 

Reference: http://www.office-loesung.de/ftopic99887_0_0_asc.php

Cheers

like image 42
GOSCHEN Avatar answered Nov 02 '22 22:11

GOSCHEN