月视图结合每一个价值

时间:2014-08-01 19:53:26

标签: vba excel-vba monthcalendar excel

我在表单中创建了Monthview和TimePicker。我希望用户选择时间,并选择一个月份,该月份将加粗每次选择的值,然后选择确定将插入值。我把这一切都搞好了。问题是,如果用户选择日期,然后选择另一个日期或其他日期,则所有日期都将获得Bolded。我希望BOLD只跟踪每个最近的点击...如果这有意义,那么用户就知道他选择了什么价值。

这是我的点击代码:

  Private Sub MonthView1_DateClick(ByVal DateClicked As Date)

 Dim x As Date

    x = MonthView1.value
    MonthView1.DayBold(x) = True ' Bold the date

End Sub

我需要什么方法?是否有某种最近点击的属性?

2 个答案:

答案 0 :(得分:1)

请尝试以下代码:

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)

Dim x As Date
Dim MaxDate As Date
Dim MinDate As Date

MinDate = DateSerial(Year(DateClicked), Month(DateClicked), 1) 'Get first date of current month based on clicked date
MaxDate = DateSerial(Year(DateClicked), Month(DateClicked) + 1, 0) 'Get last date of current month based on clicked date

x = ActiveCell.Value 'Retreive value of last Bold date
If x >= MinDate And x <= MaxDate Then 'If last Bold date is in the current month then unbold it
    MonthView1.DayBold(x) = False
End If

MonthView1.DayBold(DateClicked) = True 'Bold the clicked date
ActiveCell.Value = DateClicked 'Store current date in a sheet

End Sub

我们的想法是将粗体日期保存在工作表中(如果愿意,可以隐藏它),并在选择其他日期时检索它。粗体格式将从上一个日期中删除并应用于当前日期。

答案 1 :(得分:-1)

更多关于MonthView

中的粗体
'<code>
Private Sub CommandButton1_Click()
  Dim Ss(50) As Boolean

  'put  in module  DaysToBold$  and DatesToBold$  as public variables
  DaysToBold = "713"  ' sat Sun Tue
  ' DaysToBold = "" ' for none
  DatesToBold = "x,1,2,12,22,30"
 ' DatesToBold = "x" ' if none

  MonthView21_GetDayBold Now, 49, Ss

End Sub

Private Sub MonthView21_GetDayBold(ByVal StartDate As Date, _
            ByVal Count As Integer, State() As Boolean)
  Dim I As Integer, Mi%, DTB, DI%, DAd%
  On Error Resume Next ' seem to be  negative indices into State() even if declared  ( -10 to 50)

  For Mi = 1 To Len(DaysToBold)  ' mark of the Days of week to bold
    I = Mid(DaysToBold, Mi, 1)  ' single digits 1 ..7  excel translate to integer
    While I < Count
        State(I - MonthView21.StartOfWeek) = True
        I = I + 7  ' down the column
    Wend
  Next Mi


  DTB = Split(DatesToBold, ",")
  If UBound(DTB) > 0 Then
    With MonthView21
        For I = 1 To UBound(DTB)  ' mark the date numbers to bold
          DI = Weekday(DateSerial(Year(.Value), Month(.Value), 1), .StartOfWeek)
         If DI = 1 Then DAd = 5 Else DAd = -2  ' 7 days of last month there if Di=1
            State(DTB(I) + DI + DAd) = True
        Next I
    End With
  End If
End Sub
'</code>