在VBA中,可以使用Date
函數(shù)來返回當前日期??梢詫⒃摵瘮?shù)的返回值賦值給一個變量,并在需要的地方使用。
以下是一個示例代碼:
Sub GetCurrentDate()
Dim currentDate As Date
currentDate = Date
MsgBox "當前日期是:" & currentDate
End Sub
此代碼中,我們使用Date
函數(shù)獲取當前日期,并將其賦值給名為currentDate
的變量。然后,使用MsgBox
函數(shù)在消息框中顯示當前日期。