Option Explicit
Private Sub ExGetAgoWeek(ByRef stdate As Date, endate As Date)
Dim ttoday As Date
'曜日
Dim nWeek As Integer
'本日
ttoday = Label1.Caption
'曜日を取得する
nWeek = Weekday(ttoday)
'先週の開始日と終了日を計算
Select Case nWeek
Case vbMonday:
stdate = ttoday - 7
endate = ttoday - 1
Case vbTuesday:
stdate = ttoday - 8
endate = ttoday - 2
Case vbWednesday:
stdate = ttoday - 9
endate = ttoday - 3
Case vbThursday:
stdate = ttoday - 10
endate = ttoday - 4
Case vbFriday:
stdate = ttoday - 11
endate = ttoday - 5
Case vbSaturday:
stdate = ttoday - 12
endate = ttoday - 6
Case vbSunday:
stdate = ttoday - 13
endate = ttoday - 7
End Select
End Sub
Private Sub ExGetThisWeek(ByRef stdate As Date, endate As Date)
Dim ttoday As Date
'曜日
Dim nWeek As Integer
'本日
ttoday = Label1.Caption
'曜日を取得する
nWeek = Weekday(ttoday)
'開始日と終了日を計算
Select Case nWeek
Case vbMonday:
stdate = ttoday
endate = ttoday + 6
Case vbTuesday:
stdate = ttoday - 1
endate = ttoday + 5
Case vbWednesday:
stdate = ttoday - 2
endate = ttoday + 4
Case vbThursday:
stdate = ttoday - 3
endate = ttoday + 3
Case vbFriday:
stdate = ttoday - 4
endate = ttoday + 2
Case vbSaturday:
stdate = ttoday - 5
endate = ttoday + 1
Case vbSunday:
stdate = ttoday - 6
endate = ttoday
End Select
End Sub
'先週ボタン
Private Sub CommandButton2_Click()
Dim stdt As Date
Dim endt As Date
ExGetAgoWeek stdt, endt
Debug.Print stdt & " ~ " & endt
End Sub
'今週ボタン
Private Sub CommandButton3_Click()
Dim stdt As Date
Dim endt As Date
ExGetThisWeek stdt, endt
Debug.Print stdt & " ~ " & endt
End Sub
■■■
このサイトの内容を利用して発生した、いかなる問題にも一切責任は負いませんのでご了承下さい
■■■
当ホームページに掲載されているあらゆる内容の無許可転載・転用を禁止します