How To Get Today’s Date In Excel Vba

To get today’s date in Excel VBA, you can use the “Date” function. Here’s an example of how you can retrieve today’s date in different formats:

  
Sub GetTodaysDate()
    ' 1. Date formatted as "MM/DD/YYYY"
    Dim date1 As String
    date1 = Format(Date, "MM/DD/YYYY")
    MsgBox date1
    
    ' 2. Date formatted as "MMM DD, YYYY"
    Dim date2 As String
    date2 = Format(Date, "MMM DD, YYYY")
    MsgBox date2
    
    ' 3. Date formatted as "DD-MMM-YY"
    Dim date3 As String
    date3 = Format(Date, "DD-MMM-YY")
    MsgBox date3
    
    ' 4. Date formatted as "MMMM DD, YYYY"
    Dim date4 As String
    date4 = Format(Date, "MMMM DD, YYYY")
    MsgBox date4
End Sub
  
  

In the above VBA code, the “Format” function is used to format the date according to the desired format. The “Date” function returns the current system date.

When you run the above code, each formatted date will be displayed in a message box.

Read more

Leave a comment