vba 带有DatePicker的Excel VBA中的“对象库无效或包含引用...”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4495002/
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 11:01:23  来源:igfitidea点击:

"Object Library invalid or contains references..." in Excel VBA with DatePicker

excelvbaexcel-vbaactivexregistry

提问by CaBieberach

I have been working on a Excel workbook with lots of VBA code for a while and now I have send this file to some colleagues for testing and it does NOT work in their computer. We all work in the same company and have Windows XP SP2 with Office 2003.

我一直在处理带有大量 VBA 代码的 Excel 工作簿,现在我已将此文件发送给一些同事进行测试,但它在他们的计算机上不起作用。我们都在同一家公司工作,使用 Windows XP SP2 和 Office 2003。

The workbook has a form that opens when clicking over a shape and it contains some controls. When they click over the shape for the form to show the following error appears:

工作簿有一个在单击形状时打开的表单,它包含一些控件。当他们单击表单的形状以显示以下错误时:

"Object Library invalid or contains references to object defintions that could not be found"

“对象库无效或包含对无法找到的对象定义的引用”

In the form there is a DatePicker and I think there lies the problem. If I delete the datePicker from the form and send them the file again they do not get this error message.

在表单中有一个 DatePicker,我认为问题就在这里。如果我从表单中删除 datePicker 并再次向他们发送文件,他们不会收到此错误消息。

I already tried deleting the mscomct2.exd file as mentioned in this two sites "Microsoft" and "lessanvaezi" but the error stil pops. I checked and the new .exd file was generated.

我已经尝试删除这两个站点“ Microsoft”和“ lessanvaezi”中提到的 mscomct2.exd 文件,但错误仍然存在。我检查并生成了新的 .exd 文件。

Some Additional info:

一些附加信息:

  1. I check their system and they do have the file mscomct2.ocx in the correct location(c:\Winxp\System32).
  2. If I open a empty Excel file, go to the VBA editor go to Tools->Reference, I do NOT see the option to register the "Microsoft Common Control-2 6.0 (SP6)" (mscomct2.ocx). Instead I see a "Microsoft Windows Common Controls Satellite-3 6.2)" (cmct3de.dll).
  3. I send my collegue the file with the datePicker, but without the reference to the "Microsoft Common Control-2 6.0 (SP6)". Before clicking the shape and opening the form I tried to reference the MSCOMCT2.ocx library dinamically with the following code. It referenced the "Microsoft Common Control-2 6.0 (SP6)" but the error still pops.
  1. 我检查了他们的系统,他们确实在正确的位置(c:\Winxp\System32)有文件 mscomct2.ocx。
  2. 如果我打开一个空的 Excel 文件,请转到 VBA 编辑器转到工具->参考,我看不到注册“Microsoft Common Control-2 6.0 (SP6)”(mscomct2.ocx) 的选项。相反,我看到了“Microsoft Windows Common Controls Satellite-3 6.2)”(cmct3de.dll)。
  3. 我将带有 datePicker 的文件发送给我的同事,但没有提及“Microsoft Common Control-2 6.0 (SP6)”。在单击形状并打开表单之前,我尝试使用以下代码动态引用 MSCOMCT2.ocx 库。它引用了“Microsoft Common Control-2 6.0 (SP6)”,但错误仍然存​​在。

Sub RegisterCtl()

'MSComCt2.ocx
strGUID = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}"
ThisWorkbook.VBProject.References.AddFromGuid guid:=strGUID, Major:=1, Minor:=0

end Sub

子 RegisterCtl()

'MSComCt2.ocx
strGUID = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}"
ThisWorkbook.VBProject.References.AddFromGuid guid:=strGUID, Major:=1, Minor:=0

结束子

  1. If I then go to the form in the VBE editor and rightClick on the toolbox and then go to the Additional controls to add the "Microsoft Date and TimePicker" control, I see that option listed Two times. Unfortunatelly regarless of wich one I cchose, the behaviour is the same: The datepicker symbol is added in the toolbox, but when I drag the control to the form, a msgBox pops saying that the control was not available.
  1. 如果我然后转到 VBE 编辑器中的表单并右键单击工具箱,然后转到附加控件以添加“Microsoft Date and TimePicker”控件,我会看到该选项列出了两次。不幸的是,不管我选择了哪一个,行为都是一样的:在工具箱中添加了日期选择器符号,但是当我将控件拖到表单中时,会弹出一个 msgBox 说该控件不可用。

Has anybody an idea what is wrong? What can I do to make it run in their computer?

有人知道出了什么问题吗?我该怎么做才能让它在他们的电脑上运行?

I appreciate any help.

我很感激任何帮助。

Edit:

编辑:

The computer with this problem has been Upgraded so I wont be able to find the specific solution for my case. I'm choosing Archers solution as it has helped the most people (Most Upvotes).

出现此问题的计算机已升级,因此我无法找到适合我的案例的具体解决方案。我选择 Archers 解决方案是因为它帮助了最多的人(Most Upvotes)。

回答by Archer

I have the same problem too. http://support.microsoft.com/kb/957924/en-usdelete all .exd files make my program work!

我也有同样的问题。http://support.microsoft.com/kb/957924/en-us删除所有 .exd 文件使我的程序工作!

Go into a command prompt and type the following DOS commands:

进入命令提示符并键入以下 DOS 命令:

Code:

代码:

CD \Documents and Settings

DEL /S /A:H /A:-H *.EXD

CD \文档和设置

DEL /S /A:H /A:-H *.EXD

回答by Patrick

I had this problem. I cant remember what the reason was, but in your userform where you have the date/time picker, put this in userform_initialize. The code just adds a textbox if they do not have the correct reference. I know its not the BEST solution, but its a workaround. I wasn't able to run regsvr32 on any machines because of our system administrators.

我有这个问题。我不记得是什么原因了,但是在你有日期/时间选择器的用户表单中,把它放在 userform_initialize 中。如果没有正确的引用,代码只会添加一个文本框。我知道它不是最好的解决方案,但它是一种解决方法。由于我们的系统管理员,我无法在任何机器上运行 regsvr32。

Dim dtP As Object
Dim hasDtPicker As Boolean
On Error Resume Next
Set dtP = frmSearch.Frame24.Controls.Add("MSComCtl2.DTPicker", "DTPicker1", True)
If Err.Number <> 0 Or dtP Is Nothing Then
     hasDtPicker = False
     'change "frmsearch.Frame24" to the area where you want the date and time picker to be.
     Set dtP = frmSearch.Frame24.Controls.Add("Forms.TextBox.1", "DTPicker1", True)
     dtP.Text = [todays_date].Value
Else
     hasDtPicker = True
End If
'
' formatting properties for both TextBox and DTPicker
'
With dtP
     .Width = 67.5
     .height = 18
     .Left = lblNextActionDate.Left
     .Top = lblNextActionDate.Top + lblNextActionDate.height + 5
End With

回答by Dick Kusleika

I think #2 is the root of the problem. If you can get mscomct2.ocx to show up in Tool - References on a new workbook, it will probably fix the rest of your problems. Did you try registering the ocx? Start - Run - cmd to open a DOS window. Navigate to the system32 folder. Type

我认为#2 是问题的根源。如果您可以让 mscomct2.ocx 显示在新工作簿上的工具 - 参考中,它可能会解决您的其余问题。你试过注册ocx吗?开始-运行-cmd打开DOS窗口。导航到 system32 文件夹。类型

regsvr32 mscomct2.ocx

I think that will put the ocx in the Tools - References box and hopefully that fixes it. Here's a link for insalling the ocx on Windows 7

我认为这会将 ocx 放在工具 - 参考框中,并希望能够修复它。这是在 Windows 7 上安装 ocx 的链接

http://www.dailydoseofexcel.com/archives/2010/05/28/calendar-control-dll-on-windows-7-64-bit/

http://www.dailydoseofexcel.com/archives/2010/05/28/calendar-control-dll-on-windows-7-64-bit/

Not your situation, but maybe helpful. Also, see MS's page on regsvr32

不是你的情况,但可能有帮助。另外,请参阅 regsvr32 上的 MS 页面

http://support.microsoft.com/kb/249873

http://support.microsoft.com/kb/249873

回答by D K

I had similar problem recently. After about two days downloaded new mscomct2.ocx file: http://support.microsoft.com/kb/297381unregistered previous one, manually removed a strange MRU key with "mscomct2" in one of fields (just in case only), registered new one (using Access ActiveX menu). And all controls from mscomct2.ocx are listed only once since then !

我最近有类似的问题。大约两天后下载了新的 mscomct2.ocx 文件:http: //support.microsoft.com/kb/297381取消注册前一个,手动删除一个奇怪的 MRU 密钥,其中一个字段中带有“mscomct2”(以防万一),注册新的(使用 Access ActiveX 菜单)。从那以后,来自 mscomct2.ocx 的所有控件只列出一次!

But unfortunately that did not remove error messages. However after double consecutive import to the new container: original_file.mdb --> db1.mdb --> db2.mdb error messages do not appear any more (in the db2.mdb file). But they were still visible during trnasfer between original_file.mdb and db1.mdb.

但不幸的是,这并没有删除错误消息。但是在连续两次导入新容器后: original_file.mdb --> db1.mdb --> db2.mdb 错误消息不再出现(在 db2.mdb 文件中)。但它们在 original_file.mdb 和 db1.mdb 之间的 trnasfer 期间仍然可见。

回答by Hillyman

I am having this same problem with a file I sent to another group. I have a date picker in a user form, and the file works fine with the Excel (2007 and 2010) except for the machines in this one group. The error message is the same as in the original posting.

我发送给另一个组的文件也遇到了同样的问题。我有一个用户表单中的日期选择器,除了这一组中的机器外,该文件在 Excel(2007 和 2010)上运行良好。错误消息与原始发布中的相同。

The answer seems to be the following, as described by a support person who looked into it:

正如一位调查该问题的支持人员所描述的那样,答案似乎如下:

It turns out the MSCOMCT2.OCX file was missing from the user's computer. This file is Microsoft Windows Common Controls-2 6.0 (MSCOMCT2.OCX). It appears that this control provides the capability in the model to work with the Date Picker.

事实证明,用户计算机中缺少 MSCOMCT2.OCX 文件。此文件是 Microsoft Windows Common Controls-2 6.0 (MSCOMCT2.OCX)。似乎此控件提供了模型中使用日期选择器的功能。

The process to fix his computer was as follows:

修理他的电脑的过程如下:

  1. Copy mscomct2.ocx file to c:\windows\system32

  2. Register the ocx file by running the following command on his computer. From a command prompt type regsvr32.exe c:\windows\system32\mscomct2.ocx then press Enter.

  1. 将 mscomct2.ocx 文件复制到 c:\windows\system32

  2. 通过在他的计算机上运行以下命令来注册 ocx 文件。从命令提示符键入 regsvr32.exe c:\windows\system32\mscomct2.ocx,然后按 Enter。



This instruction may be specific to the group's computers, but the identification of mscomct2.ocx as the culprit is a start. I have no specific recommendation of where to get this file, except that it seems to be available on the internet.

此指令可能特定于该组的计算机,但将 mscomct2.ocx 识别为罪魁祸首是一个开始。我没有关于从何处获取此文件的具体建议,只是它似乎可以在 Internet 上找到。

回答by Konstantin Spirin

Try to delete startup addins from here (mind Office version):

尝试从这里删除启动插件(注意 Office 版本):

C:\Program Files\Microsoft Office\OFFICE12\XLSTART\

回答by Dasharath

Just un-register MSCOMCTL.OCXand then register it.

只需取消注册MSCOMCTL.OCX,然后再注册即可。

**32-bit OS** C:\Windows\System32\MSCOMCTL.OCX

**64-Bit OS** C:\Windows\SySWOW64\MSCOMCTL.OCX

回答by Char2d2

Check to see that the (Name) field on your DatePicker ActiveX control isn't incrementing. I have an excel sheet with a ComboBox in which the name changes everytime I open, and where it is referenced in code it throws this same error.

检查 DatePicker ActiveX 控件上的 (Name) 字段是否不递增。我有一个带有 ComboBox 的 Excel 工作表,其中每次打开时名称都会更改,并且在代码中引用它的位置会引发相同的错误。

I reference ComboBox1, but strangely it is now ComboBox17.

我参考了 ComboBox1,但奇怪的是它现在是 ComboBox17。