VBAでシリアル値を扱う場合、格納する変数の型によって出力が異なる。
・String型:日時がそのまま文字列として格納される
・Double型:シリアル値が小数以下まで格納される(日付+時間の値)
・Long型 :シリアル値が整数として格納される(日付値)
Integer型だとオーバーフローする。
※シリアル値:1日を1とした値。小数以下は時間を表す。
vba
Sub test()
Dim timeStr As String
Dim timeDbl As Double
Dim timeLng As Long
timeStr = Range("B2").Value
timeDbl = Range("B2").Value
timeLng = Range("B2").Value
Debug.Print "timeStr", timeStr
Debug.Print "timeDbl", timeDbl
Debug.Print "timeLng", timeLng
End Sub
出力結果
timeStr 2017/01/01 12:20:15
timeDbl 42736.5140625
timeLng 42737