Sub PrintLogBook()
Dim lYear As Long
Dim DayNo As Long
Dim strWeek As String
Dim dtStartWeek As Date
Dim dtEndWeek As Date
Dim wks As Worksheet
Set wks = ActiveSheet
With wks.PageSetup
.Orientation = xlLandscape ' or xlPortrait
.PrintArea = "$A$1:$R$61"
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
lYear = wks.Range("T1").Value
DayNo = VBA.Weekday(DateSerial(lYear, 1, 1), vbMonday)
dtStartWeek = DateSerial(lYear, 1, 1 - DayNo + 1)
dtEndWeek = dtStartWeek + 6
Do
strWeek = vbNullString
If Year(dtStartWeek) < lYear Then
strWeek = Year(dtStartWeek) & "/" & IIf(Right(CStr(lYear), 1) = "0", Right(CStr(lYear), 2), Right(CStr(lYear), 1)) & " WEEK " & Evaluate("=ISOWEEKNUM(" & CLng(dtStartWeek) & ")")
ElseIf Year(dtEndWeek) > lYear Then
strWeek = Year(dtStartWeek) & "/" & IIf(Right(CStr(lYear + 1), 1) = "0", Right(CStr(lYear + 1), 2), Right(CStr(lYear + 1), 1)) & " WEEK " & Evaluate("=ISOWEEKNUM(" & CLng(dtStartWeek) & ")")
Else
strWeek = Year(dtStartWeek) & " WEEK " & Evaluate("=ISOWEEKNUM(" & CLng(dtStartWeek) & ")")
End If
strWeek = strWeek & " " & UCase(Format(dtStartWeek, "MMM dd") & "-" & Format(dtEndWeek, "MMM dd"))
wks.Range("R1").Value = strWeek
wks.PrintOut Preview:=True 'after the test, change to False
dtStartWeek = dtStartWeek + 7
dtEndWeek = dtStartWeek + 6
DoEvents
Loop Until Year(dtStartWeek) > lYear
End Sub