问题

在2010年以后的office版本中,对于32位的控件支持越来越少。其中包括过往文件中正在使用的DTPicker,其原本作用是用来弹出选择界面并可以让用户选择日期作为输入的。

解决方案

其实没有太好的解决方案,暂时从github上找到了一些也许可以用的代码,有待尝试。

rkapl123/DatePicker

Dim theDatepicker2 As Object

' single Datefield setting
Private Sub Datefield_Click()
    Dim theDatepicker As Object
    Set theDatepicker = CreateObject("DatePicker.DatePicker")
    theDatepicker.Calendar.MaxSelectionCount = 1
    theDatepicker.ShowDialog
    Me.Datefield.Caption = Format(theDatepicker.StartDate, "dd.mm.yyyy")
End Sub

' Datefield range setting, first date field
Private Sub Label1_Click()
    theDatepicker2.ShowDialog
    Me.Label1.Caption = Format(theDatepicker2.StartDate, "dd.mm.yyyy")
    Me.Label2.Caption = Format(theDatepicker2.EndDate, "dd.mm.yyyy")
End Sub

' Datefield range setting, second date field
Private Sub Label2_Click()
    theDatepicker2.ShowDialog
    Me.Label1.Caption = Format(theDatepicker2.StartDate, "dd.mm.yyyy")
    Me.Label2.Caption = Format(theDatepicker2.EndDate, "dd.mm.yyyy")
End Sub

' close userform
Private Sub OKButton_Click()
    Me.Hide
End Sub

' for Datefield ranges, need to initialize the datepicker before fields are clicked
Private Sub UserForm_Initialize()
    Set theDatepicker2 = CreateObject("DatePicker.DatePicker")
    theDatepicker2.Calendar.SetCalendarDimensions 4, 3
    theDatepicker2.Calendar.MaxSelectionCount = 366
End Sub
最后修改:2022 年 08 月 23 日
如果觉得我的文章对你有用,请随意赞赏