简体   繁体   English

如何将日期选择器添加到 VBA 用户窗体

[英]How to Add Date Picker To VBA UserForm

I am looking for a control to add to userForm to enable a user to pick the date.我正在寻找一个控件来添加到 userForm 以使用户能够选择日期。 I found a good one at this address我在这个地址找到了一个很好的

Formatting MM/DD/YYYY dates in textbox in VBA 在 VBA 中的文本框中格式化 MM/DD/YYYY 日期

from Siddharth Rout which is perfect but it generates invisible sheets which is not necessary for my application.来自 Siddharth Rout,这是完美的,但它会生成我的应用程序不需要的隐形床单。 I tried to stop creating sheets but I couldn't figure it out.我试图停止创建工作表,但我无法弄清楚。

Can you please let me know how I can properly modify the Siddharth Rout code or point me to another application like that?您能否让我知道如何正确修改 Siddharth Rout 代码或将我指向另一个类似的应用程序?

Thanks for your time谢谢你的时间

OFFICE 2013 INSTRUCTIONS : OFFICE 2013说明

(For Windows 7 (x64) | MS Office 32-Bit ) (适用于Windows 7(x64) | MS Office 32位

Option 1 | 选项1 | Check if ability already exists | 检查能力是否已存在| 2 minutes 2分钟

  1. Open VB Editor 打开VB编辑器
  2. Tools -> Additional Controls 工具 - >附加控件
  3. Select "Microsoft Monthview Control 6.0 (SP6)" (if applicable) 选择“Microsoft Monthview Control 6.0(SP6)”(如果适用)
  4. Use 'DatePicker' control for VBA Userform 对VBA Userform使用'DatePicker'控件

Option 2 | 选项2 | The "Monthview" Control doesn't currently exist | “月视图”控件当前不存在| 5 minutes 5分钟

  1. Close Excel 关闭 Excel
  2. Download MSCOMCT2.cab (it's a cabinet file which extracts into two useful files) 下载 MSCOMCT2.cab (它是一个压缩成两个有用文件的cabinet文件)
  3. Extract Both Files | 提取两个文件| the .inf file and the .ocx file .inf文件和.ocx文件
  4. Install | 安装 | right-click the .inf file | 右键单击.inf文件| hit "Install" 点击“安装”
  5. Move .ocx file | 移动 .ocx文件| Move from "C:\\Windows\\system32" to "C:\\Windows\\sysWOW64" 从“C:\\ Windows \\ system32”移动到“C:\\ Windows \\ sysWOW64”
  6. Run CMD | 运行CMD | Start Menu -> Search -> "CMD.exe" | 开始菜单 - >搜索 - >“CMD.exe”| right-click the icon | 右键单击图标| Select "Run as administrator" 选择“以管理员身份运行”
  7. Register Active-X File | 注册 Active-X文件| Type "regsvr32 c:\\windows\\sysWOW64\\MSCOMCT2.ocx" 输入“regsvr32 c:\\ windows \\ sysWOW64 \\ MSCOMCT2.ocx”
  8. Open Excel | 打开 Excel | Open VB Editor 打开VB编辑器
  9. Activate Control | 激活控制| Tools->References | 工具 - >参考文献| Select "Microsoft Windows Common Controls 2-6.0 (SP6)" 选择“Microsoft Windows Common Controls 2-6.0(SP6)”
  10. Userform Controls | 用户形式控件| Select any userform in VB project | 在VB项目中选择任何用户窗体 Tools->Additional Controls 工具 - >附加控件
  11. Select "Microsoft Monthview Control 6.0 (SP6)" 选择 “Microsoft Monthview Control 6.0(SP6)”
  12. Use 'DatePicker' control for VBA UserForm 对VBA UserForm 使用 'DatePicker'控件

Okay, either of these two steps should work for you if you have Office 2013 (32-Bit) on Windows 7 (x64). 好的,如果在Windows 7(x64)上安装Office 2013(32位),这两个步骤中的任何一个都应该适合您。 Some of the steps may be different if you have a different combo of Windows 7 & Office 2013. 如果您使用Windows 7和Office 2013的不同组合,则某些步骤可能会有所不同。

The "Monthview" control will be your fully fleshed out 'DatePicker'. “月视图”控件将是您完全充实的“DatePicker”。 It comes equipped with its own properties and image. 它配备了自己的属性和图像。 It works very well. 它工作得很好。 Good luck. 祝好运。

Site: "bonCodigo" from above (this is an updated extension of his work) 网站:上面的“bonCodigo”(这是他工作的最新扩展)
Site: "AMM" from above (this is just an exension of his addition) 网站:上面的“AMM”(这只是他加入的一个例子)
Site: Various Microsoft Support webpages 站点:各种Microsoft支持网页

You could try the "Microsoft Date and Time Picker Control". 您可以尝试“Microsoft日期和时间选择器控件”。 To use it, in the Toolbox, you right-click and choose "Additional Controls...". 要使用它,请在工具箱中右键单击并选择“其他控件...”。 Then you check "Microsoft Date and Time Picker Control 6.0" and OK. 然后,您检查“Microsoft日期和时间选择控件6.0”和确定。 You will have a new control in the Toolbox to do what you need. 您将在工具箱中使用新控件来执行所需操作。

I just found some printscreen of this on : http://www.logicwurks.com/CodeExamplePages/EDatePickerControl.html Forget the procedures, just check the printscreens. 我刚刚发现了一些这方面的打印屏幕: http//www.logicwurks.com/CodeExamplePages/EDatePickerControl.html忘记程序,只需检查打印屏幕即可。

In Access 2013. Drop a "Text Box" control onto your form. 在Access 2013中。将“文本框”控件拖放到表单上。 On the Property Sheet for the control under the Format tab find the Format property. 在“格式”选项卡下的控件的“属性表”上,找到“格式”属性。 Set this to one of the date format options. 将其设置为日期格式选项之一。 Job's done. 工作完成了。

Just throw some light in to some issues related to this control. 简单介绍一下与此控件相关的一些问题。

Date picker is not a standard control that comes with office package. 日期选择器不是办公套餐附带的标准控件。 So developers encountered issues like missing date picker controls when application deployed in some other machiens/versions of office. 因此,当应用程序部署在其他一些机器/办公室版本中时,开发人员遇到了缺少日期选择器控件等问题。 In order to use it you have to activate the reference to the .dll, .ocx file that contains it. 要使用它,您必须激活对包含它的.dll,.ocx文件的引用。

In the event of a missing date picker, you have to replace MSCOMCT2.OCX file in System or System32 directory and register it properly. 如果缺少日期选择器,则必须替换System或System32目录中的MSCOMCT2.OCX文件并正确注册。 Try this link to do the proper replacement of the file. 尝试此链接以正确替换文件。

In the VBA editor menu bar-> select tools-> references and then find the date picker reference and check it. 在VBA编辑器菜单栏 - >选择工具 - >参考,然后找到日期选择器参考并检查它。

If you need the file, download MSCOMCT2.OCX from here . 如果您需要该文件,请从此处下载MSCOMCT2.OCX。

A calendar form can be used as an alternative to the date picker.日历表单可用作日期选择器的替代方法。 On a userform example, I used this calendar form to add dates to text boxes.在用户表单示例中,我使用此日历表单向文本框添加日期。 When double-clicked on the textbox, the calendar form is displayed :双击文本框时,会显示日历表单:

在此处输入图片说明

Private Sub txtDOTDate_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Call GetCalendar
End Sub

Sub GetCalendar()
    dateVariable = CalendarForm.GetDate(DateFontSize:=11, _
        BackgroundColor:=RGB(242, 248, 238), _
        HeaderColor:=RGB(84, 130, 53), _
        HeaderFontColor:=RGB(255, 255, 255), _
        SubHeaderColor:=RGB(226, 239, 218), _
        SubHeaderFontColor:=RGB(55, 86, 35), _
        DateColor:=RGB(242, 248, 238), _
        DateFontColor:=RGB(55, 86, 35), _
        TrailingMonthFontColor:=RGB(106, 163, 67), _
        DateHoverColor:=RGB(198, 224, 180), _
        DateSelectedColor:=RGB(169, 208, 142), _
        TodayFontColor:=RGB(255, 0, 0))
If dateVariable <> 0 Then frmflightstats.txtDOTDate = dateVariable
End Sub

Source of template模板来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM