如何从Excel中的UserControl日历中选择多个日期?

时间:2015-05-09 16:07:07

标签: excel vba excel-vba calendar

我在Excel中有一个userForm日历控件,它适用于单个日期。这是代码:

 If Range("C4").Value = "" Then
    ' do nothing'
 Else
    If IsDate(Range("C4").Value) = True Then
       Load frmCustomCalendarControl
       frmCustomCalendarControl.SelectedDayNumber = Day(Range("C4").Value)
       frmCustomCalendarControl.SelectedMonthNumber = Month(Range("C4").Value)
       frmCustomCalendarControl.SelectedYearNumber = Year(Range("C4").Value)
    End If
 End If
 frmCustomCalendarControl.Show
 If frmCustomCalendarControl.SelectedDayNumber = 0 And _
  frmCustomCalendarControl.SelectedMonthNumber = 0 And _
  frmCustomCalendarControl.SelectedYearNumber = 0 Then
    ' user click on the cancel button in the calendar control therefore do nothing '
 Else
    Range("C4").Value = DateSerial(frmCustomCalendarControl.SelectedYearNumber, _
     frmCustomCalendarControl.SelectedMonthNumber, _
     frmCustomCalendarControl.SelectedDayNumber)
    ' the following properties are also available from the customer control if you need them
    Debug.Print "frmCustomCalendarControl.SelectedDateDDMMYYYY = " & frmCustomCalendarControl.SelectedDateDDMMYYYY
    Debug.Print "frmCustomCalendarControl.SelectedDayString = " & frmCustomCalendarControl.SelectedDayString
    Debug.Print "frmCustomCalendarControl.SelectedMonthString = " & frmCustomCalendarControl.SelectedMonthString
    Debug.Print "frmCustomCalendarControl.SelectedYearString = " & frmCustomCalendarControl.SelectedYearString
 End If
 Unload frmCustomCalendarControl

这是运行日历UserForm并选择日期的代码。 现在我想使用相同的用户控件选择多个日期。

1 个答案:

答案 0 :(得分:0)

目前尚不清楚您使用的日历控件。我找不到任何具有代码中可见属性的日历控件。出于测试目的,我创建了一个MonthView控件。在MonthView的属性中,您可以看到:

  • $files= array(); $db = new DB; $query = $db->get_rows("SELECT * FROM `files` ORDER BY `name`"); foreach ($query as $row) { $file = new stdClass(); $file->id = $row->id; $file->name = $row->name; array_push($files,$file); } header('Content-type: application/json'); echo json_encode(array('files' => $files)); ,表示要选择的最大天数;
  • MaxSelCount - 如果是MultiSelect,则可以选择多个日期。

enter image description here