Excel中的自定义日期格式VBA

问题描述:

我正在尝试使用自定义格式将日期从英语更改为法语。常规Excel中的自定义代码是[$ -C0C] d mmmm; @并将输出作为20 juillet。Excel中的自定义日期格式VBA

当使用下面的VBA代码:

格式(范围( “B2”), “[$ -C0C] d MMMM; @”)

输出是7月20日

[ $ -C0C]应该是法国的代码加拿大

enter image description here

试试这个

'~~> Replace Sheet1 below with the sheet code name of the cell which has date 
Debug.Print Sheet1.Evaluate("text(B2, ""[$-C0C]d mmmm;@"")") 

![enter image description here

说明:如Format Function (Visual Basic for Applications)提到的格式函数只能取预定义的值中的一个。查看User-Defined Date/Time Formats (Format Function)部分,因此我们使用另一种方法。

+1

聪明! :) +1 :) – YowE3K

这为我做:

Sheet1.Range("B2").NumberFormat = "[$-C0C]d mmmm;@" 
+0

这个想法不是在Excel中更改单元格:)但是在VBA中获取值 –

+0

顺便说一句,不需要创建新的答案。你可以编辑旧版本并取消删除它 –

+0

@SiddharthRout诚实的问题,你是如何确定的? – Farmer