VBA/Excel/Access/Word/Data Type Functions/Format

Материал из VB Эксперт
Перейти к: навигация, поиск

Format$(Now, "DDD")

 
Sub FormatData()
   Debug.Print Format$(Now, "DDD")
End Sub



Format$(Now, "DDDD")

 
Sub FormatData()
   Debug.Print Format$(Now, "DDDD")
End Sub



Format$(Now, "Short Date")

 
Sub FormatData()
   Debug.Print Format$(Now, "Short Date")
End Sub



Format$(Now, "WW")

 
Sub FormatData()
   Debug.Print Format$(Now, "WW")
End Sub



Format$(Now, "YYYY")

 
Sub FormatData()
   Debug.Print Format$(Now, "YYYY")
End Sub



Format Phone number

 
Sub formatPhone()
   Debug.Print Format("1111111111", "(&&&)&&&-&&&&")
End Sub



Format Postal code

 
Sub FormatPostalCode()
  Debug.Print Format("qqqqqqqqq", "!&&&&&-&&&&")
End Sub



Illustrate the Format method

 
Sub dateFormats()
   Dim strDateString As String
   
   strDateString = "m/d/yy: " & Format(Now, "m/d/yy") & vbCrLf & _
                   "d-mmm-yy: " & Format(Now, "d-mmm-yy") & vbCrLf & _
                   "d-mmmm-yy: " & Format(Now, "d-mmmm-yy") & vbCrLf & _
                   "mmmm d, yyyy: " & Format(Now, "mmmm d, yyyy") & vbCrLf & _
                   "ddd: " & Format(Now, "ddd") & vbCrLf & _
                   "dddd: " & Format(Now, "dddd") & vbCrLf & _
                   "ddddd: " & Format(Now, "ddddd") & vbCrLf & _
                   "dddddd: " & Format(Now, "dddddd") & vbCrLf & _
                   "Hh:Nn:Ss AM/PM: " & Format(Now, "Hh:Nn:Ss AM/PM") & vbCrLf & _
                   "ttttt: " & Format(Now, "ttttt") & vbCrLf & _
                   "vbShortDate: " & FormatDateTime(Now, vbShortDate) & vbCrLf & _
                   "vbLongDate: " & FormatDateTime(Now, vbLongDate) & vbCrLf & _
                   "vbGeneralDate: " & FormatDateTime(Now, vbGeneralDate)
   
   MsgBox strDateString
End Sub



The Format function formats expressions in the style specified

 
Sub FormatData()
   Debug.Print Format$(50, "Currency")
End Sub