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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13409653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 14:26:06  来源:igfitidea点击:

How to Add Date Picker To VBA UserForm

vbaexcel-vbaexcel

提问by user1760110

I am looking for a control to add to userForm to enable a user to pick the date. I found a good one at this address

我正在寻找一个控件来添加到 userForm 以使用户能够选择日期。我在这个地址找到了一个很好的

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. I tried to stop creating sheets but I couldn't figure it out.

来自 Siddharth Rout,这是完美的,但它会生成我的应用程序不需要的隐形床单。我试图停止创建工作表,但我无法弄清楚。

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

谢谢你的时间

回答by Elias

OFFICE 2013 INSTRUCTIONS:

2013 年办公室说明

(For Windows 7 (x64)| MS Office 32-Bit)

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

Option 1 | Check if ability already exists | 2 minutes

选项 1 | 检查能力是否已经存在 | 2分钟

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

Option 2 | The "Monthview" Control doesn't currently exist | 5 minutes

选项 2 | “Monthview”控件当前不存在 | 5分钟

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

Okay, either of these two steps should work for you if you have Office 2013 (32-Bit) on Windows 7 (x64). Some of the steps may be different if you have a different combo of Windows 7 & Office 2013.

好的,如果您在 Windows 7 (x64) 上安装了 Office 2013(32 位),那么这两个步骤中的任何一个都应该适合您。如果您使用不同的 Windows 7 和 Office 2013 组合,某些步骤可能会有所不同。

The "Monthview" control will be your fully fleshed out 'DatePicker'. It comes equipped with its own properties and image. It works very well. Good luck.

“Monthview”控件将是您完全充实的“DatePicker”。它配备了自己的属性和图像。它运作良好。祝你好运。

Site: "bonCodigo" from above (this is an updated extension of his work)
Site: "AMM" from above (this is just an exension of his addition)
Site: Various Microsoft Support webpages

站点:上面的“bonCodigo”(这是他作品的更新扩展)
站点:上面的“AMM”(这只是他添加的扩展)
站点:各种 Microsoft 支持网页

回答by Matt Roy

You could try the "Microsoft Date and Time Picker Control". 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. You will have a new control in the Toolbox to do what you need.

您可以尝试“Microsoft 日期和时间选择器控件”。要使用它,请在工具箱中右键单击并选择“其他控件...”。然后检查“Microsoft 日期和时间选择器控件 6.0”并确定。您将在工具箱中有一个新控件来执行您需要的操作。

I just found some printscreen of this on : http://www.logicwurks.com/CodeExamplePages/EDatePickerControl.htmlForget the procedures, just check the printscreens.

我刚刚在以下网站上找到了一些打印屏幕:http: //www.logicwurks.com/CodeExamplePages/EDatePickerControl.html忘记程序,只需检查打印屏幕。

回答by bonCodigo

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.

日期选择器不是 office 软件包附带的标准控件。因此,当应用程序部署在其他一些机器/版本的 office 中时,开发人员遇到了诸如缺少日期选择器控件之类的问题。为了使用它,您必须激活对包含它的 .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. Try this link to dothe proper replacement of the file.

如果缺少日期选择器,您必须替换 System 或 System32 目录中的 MSCOMCT2.OCX 文件并正确注册。尝试此链接以正确替换文件。

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 。

回答by FW55

In Access 2013. Drop a "Text Box" control onto your form. 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.

在 Access 2013 中。将“文本框”控件拖放到表单上。在“格式”选项卡下控件的“属性表”上,找到“格式”属性。将此设置为日期格式选项之一。工作完成了。