2013-06-05 13 views
5

Desidero recuperare la data odierna in un formato specifico con il nome del mese inglese.Come modificare le impostazioni locali di una data formattata?

sto usando Format(DateValue(Now), "dd-mmm-yyyy"), che mi dà 05-cze-2013, che è in polacco. Quello che voglio ottenere è 05-Jan-2013.

Sono interessato solo a una soluzione VBA. Fornire anche un modo per riportare le impostazioni locali all'originale, anche utilizzando VBA.

risposta

7

Non è molto difficile ...

Sub VBA_Dates_Format() 
    Cells.Clear 
    Range("A1").Value = Now 
    Range("A2").Value = Now 
    ' Polish 
    Range("A1").NumberFormat = "[$-415]d mmm yy;@" 
    ' English UK 
    Range("A2").NumberFormat = "[$-809]d mmm yy;@" 
End Sub 

ho raggiunto questo registrando e modificando una macro per soddisfare i criteri.


Further reading available here

+0

** ** Mehow, questo è davvero impressionante. Non ho visto questo trucco fatto prima. Hai un link per ulteriori letture? Mi piacerebbe davvero capire come hai realizzato questo. – tbur

+0

@tbur ive ha registrato e modificato una macro, ma ho anche fornito un link utile nel caso in cui si volesse approfondire –

+1

Come posso farlo con una variabile String? 'Dim myDate As String: myDate = Format (DateValue (Now)," [$ -409] mmmm yyyy ")' non funziona, il mese è ancora in inglese (la mia lingua OS) ... –

0

Non è pulito VBA, ma è un modo per ottenere localizzate data formattata nella stringa. Qualcosa che la funzione Format non può fare.

With Range("$A$1") 
    .NumberFormat = "[$-809]dd mmmm" 
    .FormulaR1C1 = "=NOW()" 
    tmp = .Text 
    .NumberFormat = "@" 
    .Value = CStr(tmp) 
End With 

Maggiori informazioni sulla formattazione localizzati i grande risposta https://stackoverflow.com/a/899290 da Ian Boyd

Problemi correlati