|
楼主 |
发表于 2018-11-5 16:40
|
显示全部楼层
本帖最后由 一指禅62 于 2018-11-12 15:12 编辑
看了您的帖子,与您的撞车了。向您学习。
类模块代码
- Private Sub lblSet_Click()
- If t > #12/31/2099# Or t < #1/1/1901# Then Exit Sub
- Select Case lblSet.Caption
- Case ">": t = DateAdd("m", 1, t) '月度增加1
- Case "<": t = DateAdd("m", -1, t) '月度减少1
- Case "》": t = DateAdd("yyyy", 1, t) '年度增加1
- Case "《": t = DateAdd("yyyy", -1, t) '年度减少1
- End Select
- Call AddDate
- End Sub
复制代码
模块代码
- Sub AddDate()
- Dim t0 As Date, t1 As Date, t2 As Date, i%
- t1 = DateSerial(Year(t), Month(t), 1)
- t2 = DateSerial(Year(t), Month(t) + 1, 1) - 1
- 't0 = IIf(Weekday(t1, vbMonday) = 7, t1, t1 - Weekday(t1, vbMonday))
- t0 = t1 - Weekday(t1, vbMonday) '星期日为每周第1天
- With UserForm1
- .lblYyyyMm = Format(t, "yyyy年mm月")
- For i = 0 To 41 '对42个日期Label控件赋值
- With .Controls("lblD" & i + 1)
- .Caption = Day(t0 + i) ' 显示几日
- .ControlTipText = 农历(t0 + i) ' 提示文本显示农历
- .Tag = t0 + i ' 记录日期
- .ForeColor = IIf(t0 + i = Date, &HFF&, IIf((t0 + i < t1) Or (t0 + i > t2), &H80000002, &H80000012))
- End With
- Next
- End With
- End Sub
复制代码
|
|