Private Sub CommandButton1_Click()
Dim strTaisyo, date1, mydate, warekiNen, yy, mm, dd
strTaisyo = "20240401"
date1 = Format(strTaisyo, "####/##/##")
mydate = CDate(date1)
ActiveSheet.Cells(2, 3).Value = "date1=" & date1
ActiveSheet.Cells(3, 3).Value = "mydate=" & mydate
yy = Year(mydate)
mm = Month(mydate)
dd = Day(mydate)
ActiveSheet.Cells(4, 3).Value = "yy=" & yy & " mm=" & mm & " dd=" & dd
yy = Format(mydate, "YYYY")
mm = Format(mydate, "mm")
dd = Format(mydate, "dd")
ActiveSheet.Cells(5, 3).Value = "yy=" & yy & " mm=" & mm & " dd=" & dd
End Sub
實行結果: