2017-07-04 36 views
0

我正在嘗試使用自定義格式將日期從英語更改爲法語。常規Excel中的自定義代碼是[$ -C0C] d mmmm; @並將輸出作爲20 juillet。Excel中的自定義日期格式VBA

當使用下面的VBA代碼:

格式(範圍( 「B2」), 「[$ -C0C] d MMMM; @」)

輸出是7月20日

[ $ -C0C]應該是法國的代碼加拿大

回答

2

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

0

這爲我做:

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

這個想法不是在Excel中更改單元格:)但是在VBA中獲取值 –

+0

順便說一句,不需要創建新的答案。你可以編輯舊版本並取消刪除它 –

+0

@SiddharthRout誠實的問題,你是如何確定的? – Farmer