|
请参考:Private Sub cmdDay_Click(strDay As String, nNowMonth As Integer)
Dim dtFirstDate As Date
Dim ln As Long
Dim TextFANGSHI As Integer
' 选择后:本月第一天
dtFirstDate = DateSerial(Val(Replace(Replace(cmbYear.Text, "年", ""), "月", "")), Val(Replace(Replace(cmbMonth.Text, "年", ""), "月", "")), 1)
' 计算被选择的是:哪个月的哪一天
Dim PubSelDate As Date
PubSelDate = DateAdd("m", nNowMonth, dtFirstDate)
PubSelDate = DateSerial(Year(PubSelDate), Month(PubSelDate), Val(strDay))
' 恢复其他控件设置
For ln = 0 To 41 '//遍历所有日期按钮
If cmdDay(ln).Caption = strDay And cmdDay(ln).Tag = nNowMonth Then
cmdDay(ln).SetFocus
cmdDay(ln).Font.Bold = True
cmdDay(ln).BackColor = vbYellow
Else
cmdDay(ln).Font.Bold = False
If cmdDay(ln).Tag <> 0 Then
cmdDay(ln).BackColor = RGB(192, 192, 192) ' 非本月日期为灰色
Else
If Val(Replace(Replace(cmbYear.Text, "年", ""), "月", "")) = Year(Now) And Val(Replace(Replace(cmbMonth.Text, "年", ""), "月", "")) = Month(Now) And Val(cmdDay(ln).Caption) = Day(Now) Then
cmdDay(ln).Font.Bold = True
cmdDay(ln).BackColor = vbCyan
Else
cmdDay(ln).BackColor = vbWhite
End If
End If
End If
Next
If TextFANGSHI = 1 Then
PubDateControl.Text = Format(PubSelDate, "yyyy-MM-dd")
Else
ActiveCell.Value = Format(PubSelDate, "yyyy-MM-dd")
End If
Unload Me
End Sub |
|