Windows XP Excel VBA 在 Windows 7 上崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11539744/
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
Windows XP Excel VBA Crashes on Windows 7
提问by Gionata
I am trying to switch a Excel VBA macro from Windows XP to Windows 7. Both of the Windows versions are 32-bit operating systems. My Windows 7 version is Enterprise edition.
我正在尝试将 Excel VBA 宏从 Windows XP 切换到 Windows 7。两个 Windows 版本都是 32 位操作系统。我的 Windows 7 版本是企业版。
The VBA code works fine on Windows XP. When I have tried to run the code on Windows 7, it crashes and reports no error description.
VBA 代码在 Windows XP 上运行良好。当我尝试在 Windows 7 上运行代码时,它崩溃并且没有报告错误描述。
I have registered msinet.ocx
, which appears to be required for Microsoft Internet Transfer Control 6.0. I have also tried to fix security issues by adding the additional com components tabctl32
, comctl332/232/32
and comdlg32
, all of which are ocx files. However, nothing changes - my code still fails on Windows 7.
我已注册msinet.ocx
,这似乎是 Microsoft Internet Transfer Control 6.0 所必需的。我还尝试通过添加额外的 com 组件来解决安全问题tabctl32
,comctl332/232/32
并且comdlg32
,所有这些都是 ocx 文件。但是,没有任何变化 - 我的代码在 Windows 7 上仍然失败。
Once msinet
was unregistered, Excel VBA opens my Workbook, reports the missing reference msinet
and does not work at all. How do I resolve this issue?
一旦msinet
取消注册,Excel VBA 就会打开我的工作簿,报告缺少的参考msinet
并且根本不起作用。我该如何解决这个问题?
回答by Nigel Heffernan
Awkward. Open the sheet in an Excel session with Macro Security set to high or medium, and reply 'No' to the dialogue about enabling VBA macros in the sheet.
尴尬的。在宏安全设置为高或中的 Excel 会话中打开工作表,然后对有关在工作表中启用 VBA 宏的对话框回复“否”。
If it opens, you should still be able to view the project, and this might show an obvious missing reference or an error if you attempt to compile it.
如果它打开,您应该仍然能够查看该项目,如果您尝试编译它,这可能会显示明显的缺失引用或错误。
Next: save the workbook as html and close Excel. Clear the temp folder, restart excel, open the html file and save it back into Excel format. If you're lucky, all the legacy objects and references will be cleared out and replaced by versions compatible with your new OS.
下一步:将工作簿另存为 html 并关闭 Excel。清除临时文件夹,重新启动 excel,打开 html 文件并将其保存回 Excel 格式。如果幸运的话,所有遗留对象和引用都将被清除并替换为与您的新操作系统兼容的版本。
This works about half the time.
这大约有一半的时间。
回答by CaBieberach
The system not crashing when msinet.ocx is not registered doesnt necessary means that it is the problem.
未注册 msinet.ocx 时系统不会崩溃并不意味着这是问题所在。
If you have a call to that library (msinet.ocx) in any procedure inside ofor called fromthe ThisWorkbook
module and you have that library unregistered, then when the file opens and tries to run the On open macro the module will not compile and therefore wont run the line of code that makes it crash. (I am only guessing that this might be your case.)
如果您在模块内部或从ThisWorkbook
模块调用的任何过程中调用该库 (msinet.ocx)并且您未注册该库,则当文件打开并尝试运行 On open 宏时,该模块将无法编译,因此不会运行使其崩溃的代码行。(我只是猜测这可能是你的情况。)
Try to find out which exact call makes your system crash.
尝试找出导致系统崩溃的确切调用。
- Let msinet.ocx registered.
- Open the file without activating the macros.
- Then manually run Step by Step (F8) through the opening code of your file (
Private Sub Workbook_Open()
)
- 让 msinet.ocx 注册。
- 打开文件而不激活宏。
- 然后通过文件的打开代码手动运行 Step by Step (F8) (
Private Sub Workbook_Open()
)
Eventually you will reach the exact line of code that makes your system crash. Whit that information you will be able to get more help.
最终,您将到达导致系统崩溃的确切代码行。有了这些信息,您将能够获得更多帮助。
NOTE:
笔记:
To open the file without activating the macros you can use one of the following methods:
要在不激活宏的情况下打开文件,您可以使用以下方法之一:
Press and keep pressed the Shift key after you doubleclicked on the file to open it(from the windows explorer). For this method to work, the Excel application must be clossed.
If the Excel application is open, then go to the VB editor and type
application.EnableEvents=False
in the immediate window (and press enter to run it). Just be aware that this will disable the events on every file in that instance of Excel. You will have to set it back to true or close the application (not just the file).
双击文件打开它(从 Windows 资源管理器)后,按住 Shift 键。要使此方法起作用,必须关闭 Excel 应用程序。
如果 Excel 应用程序已打开,则转到 VB 编辑器并
application.EnableEvents=False
在即时窗口中键入(然后按 Enter 运行它)。请注意,这将禁用该 Excel 实例中每个文件上的事件。您必须将其设置回 true 或关闭应用程序(不仅仅是文件)。
回答by Michal
Check if you don't have references to missing libraries, if so simply uncheck it. I had a similar problem and it helped in my case.
检查您是否没有对缺失库的引用,如果是,只需取消选中它。我遇到了类似的问题,这对我有帮助。