|
在模块1中,把以下两段代码重贴一下即可。过程名称就不改了。
年份会自动增加的。For 循环中用的是函数 Year(Date),取当天日期所在年份。
- ' 子过程:建立弹出菜单(年日月)
- Sub Menu_Date(BarMain As CommandBar)
- Dim BarDate As CommandBarPopup
- Dim iYear As Integer
-
- Set BarDate = BarMain.Controls.Add(Type:=msoControlPopup)
- With BarDate
- .caption = "年月日"
-
- ' 建立 年份 菜单项
- For iYear = 2000 To Year(Date)
- ' 建立(月、日)子菜单项
- Call Menu_Date_YearGroup(BarDate, iYear)
- Next
- End With
-
- Set BarDate = Nothing
- End Sub
- ' 根据年份,建立(月、日)子菜单项
- Private Sub Menu_Date_YearGroup(BarParent As CommandBarPopup, iYear As Integer)
- Dim BarYear As CommandBarPopup, BarMonth As CommandBarPopup, BarDay As CommandBarButton
- Dim iMonth As Integer, iDay As Integer, iDayEnd As Integer
- Set BarYear = BarParent.Controls.Add(Type:=msoControlPopup)
- With BarYear
- .caption = iYear
- For iMonth = 1 To 12
- Set BarMonth = .Controls.Add(Type:=msoControlPopup)
- With BarMonth
- .caption = iMonth
- Select Case iMonth
- Case 1, 3, 5, 7, 8, 10, 12: iDayEnd = 31
- Case 4, 6, 9, 11: iDayEnd = 30
- Case 2: iDayEnd = Day(DateSerial(iYear, 3, 0)) ' 解决闰年问题
- End Select
- For iDay = 1 To iDayEnd
- Set BarDay = .Controls.Add(Type:=msoControlButton)
- With BarDay
- .caption = iDay
- .OnAction = "Menu_Date_Write(" & iYear & "," & iMonth & "," & iDay & ")"
- End With
- Next
- End With
- Next
- End With
- End Sub
复制代码 |
评分
-
查看全部评分
|