vba ActiveX 控件损坏?“无法退出设计模式,因为无法创建控件“DTPicker1””

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

Corrupted ActiveX control? "Can't exit design mode because Control 'DTPicker1" can not be created"

excelvbaactivexobject

提问by BillD

I am developing an Excel VBA application on my desktop machine. I have a DatePicker ActiveX control on my spreadsheet. It was working fine.

我正在台式机上开发 Excel VBA 应用程序。我的电子表格上有一个 DatePicker ActiveX 控件。它工作正常。

Then, while on travel, I was working on the application on a laptop. When I returned, I moved the file back to my desktop machine. Now when I try to run the app, I continually get the error "Can't exit design mode because Control 'DTPicker1" can not be created".

然后,在旅途中,我在笔记本电脑上开发应用程序。当我回来时,我将文件移回我的台式机。现在,当我尝试运行该应用程序时,我不断收到错误“无法退出设计模式,因为无法创建控件 'DTPicker1””。

Renaming the control and all its references in the code hasn't helped. When I try to delete the control I still get the message even though there is no longer a control of that name.

在代码中重命名控件及其所有引用并没有帮助。当我尝试删除控件时,即使不再有该名称的控件,我仍然收到消息。

How do I fix this?

我该如何解决?

回答by Jean-Fran?ois Corbett

Sounds like something in your workbook got corrupted. Something like this has happened to me once or twice.

听起来您的工作簿中的某些内容已损坏。这样的事情在我身上发生过一两次。

The solution is then to copy everything (code and sheet contents) to a new workbook and rebuild your application there.

然后解决方案是将所有内容(代码和工作表内容)复制到新工作簿并在那里重建您的应用程序。

[Upgraded from comment since this solved the issue.]

[从评论升级,因为这解决了问题。]

回答by raca

In my case, an error occurred when I developed an excel sheet with ActiveX DTPicker control in MS Excel 2013, moved it to Excel 2010 (still working), saved some changes and moved it back to the development environment in Excel 2013 - DTPickers cannot be loaded.

就我而言,当我在 MS Excel 2013 中使用 ActiveX DTPicker 控件开发 Excel 工作表时发生错误,将其移至 Excel 2010(仍在工作),保存一些更改并将其移回 Excel 2013 中的开发环境 - DTPickers 不能加载。

After some internet investigation I found a bit tricky manual how to solve the issue:

经过一些互联网调查,我发现了一个有点棘手的手册如何解决这个问题:

  1. Open the project code and unload the References that Excel allows.
  2. Make some little change in your code (I added one comment line) - to reload the project or something like that.
  3. Run some macro, for example only the one activating the first sheet.
  4. Close and reopen the Excel.
  5. Voila - Date and time pickers are loaded correctly.
  1. 打开项目代码并卸载 Excel 允许的引用。
  2. 对你的代码做一些小改动(我添加了一个注释行) - 重新加载项目或类似的东西。
  3. 运行一些宏,例如只有激活第一张表的宏。
  4. 关闭并重新打开 Excel。
  5. 瞧 - 日期和时间选择器已正确加载。

As a firs I deleted the temporary files in "C:\Users\xxx\AppData\Local\Temp\Excel8.0" but it did not helped as a standalone action, so I don't know, if it is a useful action or not.

首先,我删除了“C:\Users\xxx\AppData\Local\Temp\Excel8.0”中的临时文件,但作为独立操作没有帮助,所以我不知道它是否有用或不。

回答by JoeBloggs

Had a similar issue where "Control 'CommandButton13' can not be created". The spreadsheet still worked on my colleagues PC. I spotted in the VBA editor that Sheet13 had become renamed to CommandButton1. On my colleagues PC, we changed the name back to Sheet13. It now works OK on my PC.

有一个类似的问题,即“无法创建控件‘CommandButton13’”。该电子表格仍然可以在我同事的 PC 上运行。我在 VBA 编辑器中发现 Sheet13 已重命名为 CommandButton1。在我同事的 PC 上,我们将名称改回 Sheet13。它现在可以在我的 PC 上正常运行。

回答by SekeRob2

Years later, stumbled on a solution, only because I recorded the steps that led up to the situation.

多年后,偶然发现了一个解决方案,只是因为我记录了导致这种情况的步骤。

1) Had changed all worksheet securities to include UserInterfaceOnly:= True 2) Active-X controls were on protected sheets

1) 已将所有工作表安全更改为包括 UserInterfaceOnly:= True 2) Active-X 控件位于受保护的工作表上

The Workbook:Open included a routine to refresh all the sheet protections, something needed for UserInterfaceOnly to work, allowing macros to make sheet changes, but not the user. Always the newest Active-X control gave the 'Can't Exit Design Mode because..." or if the project is protected altogether, a 57121 error, which is catastrophic if trying to switch the offered Debug mode. Saving the workbook with the sheet that has the newest AC on it and reopening gave no issue.

Workbook:Open 包括一个刷新所有工作表保护的例程,这是 UserInterfaceOnly 工作所需的东西,允许宏进行工作表更改,而不是用户。总是最新的 Active-X 控件给出“无法退出设计模式,因为...”或者如果项目完全受到保护,则会出现 57121 错误,如果尝试切换提供的调试模式,这是灾难性的。使用上面有最新 AC 并重新打开的工作表没有问题。

Solution: Copied the protection loop at bottom to the top of Workbook_Open and changed protect to unprotect password(whatever yours is). Now the workbooks open again without any of these 2 warnings. Added the protection loop also to the Before_Safe to ensure the workbook would always be in a secure state, in case it gets loaded on a macro disabled system.

解决方案:将底部的保护循环复制到 Workbook_Open 的顶部并将保护更改为取消保护密码(无论您的密码是什么)。现在工作簿再次打开,没有任何这两个警告。还向 Before_Safe 添加了保护循环,以确保工作簿始终处于安全状态,以防它被加载到禁用宏的系统上。