vba Excel 文件中的 ActiveX 控件在某些计算机上出现“无法加载对象...”错误

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

ActiveX control in a Excel file gives "Could not load an object..." error on some machines

excelvbacomactivex

提问by Pavel Zhuravlev

We are using a set of Excel files on several machines in our company. These files contain a VBA application which utilizes a couple of ActiveX control objects from mscomct2.ocxlibrary (namely, MonthViewand DateTimePicker). ActiveX objects are to be displayed in UserForm. Unfortunately the portability of these files seems limited in a very peculiar way.

我们在我们公司的几台机器上使用一组 Excel 文件。这些文件包含一个 VBA 应用程序,它利用mscomct2.ocx库中的几个 ActiveX 控件对象(即,MonthViewDateTimePicker)。ActiveX 对象将显示在用户窗体中。不幸的是,这些文件的可移植性似乎以一种非常奇特的方式受到限制。

There appears to be 2 groups of machines:

似乎有两组机器:

  • Group A:I can create a Excel file containing MonthViewon such machine and work with it on any Group A PC. But when I try to open this file on any machine from Group B, I'm getting a Could not load an object because it is not available on this machineerror. However, files with the same ActiveX created on Group B machines work normaly on A machines.
  • Group B:File with an ActiveX in question created on these machines work everywhere (i.e. on any A and B machine). But, as I said earlier, B machines give the error mentioned above when the file with ActiveX saved on A machine is opened.
  • A 组:我可以MonthView在这样的机器上创建一个 Excel 文件,并在任何 A 组 PC 上使用它。但是当我尝试在 B 组的任何机器上打开此文件时,我收到无法加载对象,因为它在这台机器上不可用错误。但是,在 B 组机器上创建的具有相同 ActiveX 的文件在 A 机器上正常工作。
  • B 组:在这些机器上创建的带有问题的 ActiveX 的文件在任何地方都可用(即在任何 A 和 B 机器上)。但是,正如我之前所说的,当打开A机器上保存的带有ActiveX的文件时,B机器会出现上述错误。

In one sentence: files created on A machine work only on other A's, files created on B's work everywhere!

一句话:在A机器上创建的文件只能在其他A机器上工作,在B机器上创建的文件无处不在

The strangest thing here is that every machine has mscomct2.ocxregistered (once again: I can create the form with the MonthViewon any machine in question!). The .ocxitself is in place on each machine and the whole set of registry keys is present (CLSIDs for controls classes, IIDs, typelib ID...). In addition, the data in these registry keys seem to be the same on A and B group machines (GUIDs, ProgIDs, versions etc.). There are slight differences in description strings (values like "Microsoft MonthView Control 6.0 (SP6)") on some machines but this does not seem to affect the situation (some machines in B group have such descriptions different but files created on them still work everywhere).

这里最奇怪的是每台机器都已经mscomct2.ocx注册(再一次:我可以MonthView在任何有问题的机器上创建表单!)。它.ocx本身在每台机器上就位,并且存在整套注册表项(控件类的 CLSID、IID、typelib ID...)。此外,这些注册表项中的数据在 A 组和 B 组计算机上似乎相同(GUID、ProgID、版本等)。某些机器上的描述字符串(如“Microsoft MonthView Control 6.0 (SP6)”之类的值)略有不同,但这似乎不影响情况(B 组中的某些机器有这样的描述不同,但在它们上创建的文件仍然可以在任何地方使用)。

Naturally, thanks to Murphy's law, the machine I use to edit these Excel files belongs to Group A, so files saved here are 'unportable' to B machines...

自然,由于墨菲定律,我用来编辑这些 Excel 文件的机器属于 A 组,所以这里保存的文件对于 B 机器“不可移植”......

The OS and Excel versions don't seem to affect the situation. For example, one of B machines is working under Win 7 64 bit (Excel 2007), while most others group A and B machines are Win XP Prof (32 bit) SP3, with Excel 2003 installed. So it seems that OS and Excel versions don't affect compatibility and the problem is somehow connected with ActiveX.

操作系统和 Excel 版本似乎不会影响这种情况。例如,其中一台 B 机器在 Win 7 64 位 (Excel 2007) 下运行,而大多数其他 A 组和 B 组机器是 Win XP Prof (32 位) SP3,安装了 Excel 2003。所以似乎 OS 和 Excel 版本不影响兼容性,问题与 ActiveX 有某种联系。

The only ActiveX-related difference between A and B groups I found is the file version of mscomct2.ocx: at least several of A machines have version 6.1.x.x, while Group B has 6.0.x.x. I don't see how can such difference cause problems (ActiveX are COM objects after all, and according to registry key values, the exposed typelib, com objects and interfaces seem to be the same in all cases). Nevertheless I tried to replace my 6.1.x.x ocxwith 6.0.x.x version... and ran into more trouble. What I did is:

我发现 A 组和 B 组之间唯一与 ActiveX 相关的差异是文件版本mscomct2.ocx:至少有几台 A 机器的版本是 6.1.xx,而 B 组的版本是 6.0.xx 我不明白这种差异怎么会导致问题( ActiveX 毕竟是 COM 对象,根据注册表键值,暴露的 typelib、com 对象和接口似乎在所有情况下都相同)。尽管如此,我还是尝试将 6.1.xx 替换ocx为 6.0.xx 版本……但遇到了更多麻烦。我所做的是:

  1. regsvr32 /u mscomct2.ocx- completed successfully
  2. Replaced the mscomct2.ocxwith file of 6.0.x.x version
  3. regsvr32 mscomct2.ocx- completed successfully
  1. regsvr32 /u mscomct2.ocx- 成功完成
  2. 替换了mscomct2.ocx6.0.xx 版本的with 文件
  3. regsvr32 mscomct2.ocx- 成功完成

After these steps I tried to make an Excel file with single form containing the MonthView. But when I tried to place a control in the form I've got a messagebox with error Class not registered. This is really strange cause everything seem to be registered: the control class, its interfaces, typelib (yes, I've checked the registry to be sure). But still the error was there.

在这些步骤之后,我尝试制作一个包含MonthView. 但是当我试图在表单中放置一个控件时,我得到了一个消息框,错误Classnotregistered 。这真的很奇怪,因为一切似乎都已注册:控件类、它的接口、类型库(是的,我已经检查了注册表以确保)。但错误仍然存​​在。

After that I did the unregister/replace/register procedure again to go back to my original 6.1.x.x file. That took me back to the original SNAFU situation: I could again install ActiveX to user form and use it, but the Group B machines still gave the error on files saved by my machine.

之后,我再次执行取消注册/替换/注册程序以返回到我原来的 6.1.xx 文件。这让我回到了最初的 SNAFU 情况:我可以再次将 ActiveX 安装到用户表单并使用它,但是 B 组机器仍然在我的机器保存的文件上出现错误。

I assume that the problem of files-with-ActiveX portability and the problem of ocxregistration are somehow connected, but I don't see how. Perhaps there are some additional requirements for registration of an ActiveX in Excel VBA which I don't know...

我认为文件与 ActiveX 的可移植性问题和ocx注册问题有某种联系,但我不知道如何联系。也许在 Excel VBA 中注册 ActiveX 有一些我不知道的额外要求......

The only thing I need is to have the ActiveX object contaned in my Excel file compatible with other machines. Can anyone help me with that?

我唯一需要的是让我的 Excel 文件中包含的 ActiveX 对象与其他机器兼容。任何人都可以帮助我吗?

回答by Soonts

I think one group (probably "A") has this installed: http://www.microsoft.com/download/en/details.aspx?id=10019, another one don't.

我认为一组(可能是“A”)安装了这个:http: //www.microsoft.com/download/en/details.aspx?id=10019,另一组没有。