如何在Excel中创建每月/每年的日历
发布网友
发布时间:2022-04-24 17:56
我来回答
共1个回答
热心网友
时间:2023-10-28 23:57
这样的格式满足吗,VBA 代码如下?需要的话我也可以把表格寄给你~
Sub 日历()
Dim WkName As String
Dim i, j, k, l As Long
Dim strStar As Date
Dim strEnd As Date
strStar = InputBox("日历编辑起始日期", "日历编辑", #1/1/2018#)
If strStar <> False Then
strEnd = InputBox("日历编辑终止日期", "日历编辑", #5/1/2018#)
If strEnd <> False Then
WkName = WeekdayName(Weekday(Format(strStar, "yyyy/mm/dd")))
Range("A1") = Year(strStar) & "年" & Month(strStar) & "月"
Range("A1:G1").Merge
Range("A1:G1").HorizontalAlignment = xlHAlignCenter
Range("A2:G2") = Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")
For i = 3 To 1000
t = Month(strStar)
For j = 1 To 7
For k = 1 To 7
If WkName = Cells(2, k) Then
Cells(i, k) = Day(strStar)
Exit For
End If
Next
strStar = strStar + 1
If strStar > strEnd Then
Exit Sub
End If
WkName = WeekdayName(Weekday(strStar))
l = Month(strStar)
If l <> t Then
i = i + 2
Range("A" & i & ":G" & i) = Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")
Range("A" & i - 1) = Year(strStar) & "年" & Month(strStar) & "月"
Range("A" & i - 1 & ":G" & i - 1).Merge
Range("A" & i - 1 & ":G" & i - 1).HorizontalAlignment = xlHAlignCenter
Exit For
End If
If k = 7 Then
Exit For
End If
Next
Next
End If
End If
End Sub