
年月日と時分秒を指定して日付と時刻を作成するマクロです。
DateSerial関数
年月日から日付を作成するにはDateSerial関数を使います。Sub GetDateSerial() Dim nowDate As Date nowDate = DateSerial(2017, 7, 17) MsgBox nowDate End Sub
実行結果

TimeSerial関数
時分秒から時刻を作成するにはTimeSerial関数を使います。Sub GetTimeSerial() Dim nowTime As Date nowTime = TimeSerial(18, 40, 50) MsgBox nowTime End Sub
実行結果

<参考サイト>
DateSerial 関数 (Visual Basic) | MSDNライブラリ
TimeSerial 関数 (Visual Basic) | MSDNライブラリ
スポンサーリンク