2015-05-09 88 views
0

我有一個userForm日曆控件在Excel中可以正常工作的單一日期。以下是代碼:如何從Excel中的UserControl日曆中選擇多個日期?

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 

這是運行日曆用戶窗體並選擇日期的代碼。 現在我想使用相同的用戶控件選擇多個日期。

回答

0

您不清楚您使用的是什麼日曆控件。我找不到任何具有您的代碼中看到的屬性的日曆控件。出於測試目的,我創建了一個MonthView控件。在MonthView的屬性中,您可以看到:

  • MaxSelCount,它表示要選擇的最大天數;
  • MultiSelect - 如果是True,則可以選擇多於1個日期。

enter image description here

因爲日曆控件和月視圖控件
+0

不是所有版本的Excel中我一直在使用標籤和切換按鈕 –

+0

你可以分享的截圖,以便我們能想象的情況做了我自己的日曆支持更好? – ZygD

相關問題