【问题标题】:How to select multiple dates from UserControl calendar in Excel?如何从 Excel 中的 UserControl 日历中选择多个日期?
【发布时间】:2015-07-20 10:51:20
【问题描述】:

我在 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

这是运行日历用户窗体并选择日期的代码。 现在我想使用同一个用户 Control 选择多个日期。

【问题讨论】:

    标签: vba excel calendar


    【解决方案1】:

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

    • MaxSelCount,代表最多可以选择的天数;
    • MultiSelect - 如果是 True,您可以选择超过 1 个日期。

    【讨论】:

    • 由于不是所有版本的 excel 都支持日历控件和月视图控件,因此我使用标签和切换按钮制作了自己的日历
    • 您能否分享一个屏幕截图,以便我们更好地想象当时的情况?
    猜你喜欢
    • 1970-01-01
    • 2015-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多