用excel vba写的日历部分代码如下
Private Sub Calendar(ByVal iyear, ByVal imonth)
For icol = 1 To 7
For irow = 3 To 8
Cells(irow, icol) = ""
Next
Next
iday = DateSerial(iyear, imonth, 1) '取得相应年月第一天的日期
irow = 3
icol = Weekday(iday) '计算该天是星期几
Do
Cells(irow, icol) = Day(iday) '在单元格填入日期
If Weekday(iday) = vbSaturday Then '星期六则的换行
irow = irow + 1
icol = 1
Else
icol = icol + 1
End If
iday = DateAdd("d", 1, iday) '日期递增
Loop While (Day(iday)) <> 1
End Sub
1