Excel 2003在64位Windows 7会自动更改参考Syswow64资料\ MSCOMCTL.OCX所以32位Excel的抱怨 [英] Excel 2003 on 64-bit Windows 7 automatically changes reference to SysWOW64\MSCOMCTL.OCX so 32-bit Excel complains

查看:372
本文介绍了Excel 2003在64位Windows 7会自动更改参考Syswow64资料\ MSCOMCTL.OCX所以32位Excel的抱怨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个Excel 2003 VBA项目,我用从MSCOMCTL.OCX控制。这是VBA项目引用了SYSTEM32 \ MSCOMCTL.OCX。

当我打开该项目在Excel 2003在我的64位Windows 7系统,Excel会自动更改参考Syswow64资料\ MSCOMCTL.OCX(这是正确的位置)。

然而,当我发送的项目谁正在使用32位的Windows XP我的客户,该项目开盘时抱怨,因为Syswow64资料\ MSCOMCTL.OCX并不在他的系统中存在。

下面是(不可)的解决方案,我想出了至今:

  1. 指示客户端手动更改引用回到正确的位置上他的系统(SYSTEM32 \ MSCOMCTL.OCX)。

    • 在此并没有真正原因如下工作:
      1. 在Excel 2003中的32位将打开表,它无法找到引用MSCOMCTL,它会删除所有来自库(如TREECTRL)从形式控制: - (
      2. 在客户端挣扎的过程,这是非常麻烦他了。
  2. 自动更正使用VBA的VBProject.References.AddFromFile / AddFromGuid参考。
    • 在与上面相同的问题:当VBA的打开工作簿时编译失败,Excel将删除所有控件,它找不到的形式
  3. 自动添加引用(如2),并使用动态绑定在运行时添加所有相关的控制。
    • 这可能实际工作,但目前我挣扎的事件处理程序绑定的控件(但是这将是单独的问题; - )

接近1和2并没有真正解决任何问题与解决方案3是一个大量的工作。

任何想法将大大AP preciated。

解决方案

如果你自动关闭的关闭引用工作簿时关闭?这样的引用不会'破'时,打开工作簿时,所有的控制应该还是不错的。

即。

 私人小组Workbook_Open()
使用文件夹LOCS ENVIRON变量
如果OS =64然后
    Me.VBProject.References.AddFromFile(C:\ WINDOWS \ Syswow64资料\ MSCOMCTL.OCX)
其他
    Me.VBProject.References.AddFromFile(C:\ WINDOWS \ SYSTEM32 \ MSCOMCTL.OCX)
结束如果
结束小组

私人小组Workbook_BeforeClose(取消正如布尔)
    对于每一个裁判在Me.VBProject.References
       如果ref.Name =MSComctlLib然后
        Me.VBProject.References.Remove裁判
       结束如果
        接下来裁判
结束小组
 

我做了一个快速测试与ADODB DLL,它似乎工作,但我不知道你是如何使用该DLL明确;让我知道如果这样的作品,但!肯定有很多比选项3更好!

In an Excel 2003 VBA project I am using controls from MSCOMCTL.OCX. That is the VBA project has a reference to System32\MSCOMCTL.OCX.

When I open that project in Excel 2003 on my 64-bit Windows 7 system, Excel automatically changes the reference to SysWOW64\MSCOMCTL.OCX (which is the correct location).

However, when I send that project to my client who is using 32-bit Windows XP, the project complains during opening because SysWOW64\MSCOMCTL.OCX does not exist on his system.

Here are the (unsatisfactory) solutions I came up with so far:

  1. Instruct the client to manually change the reference back to the correct location on his system (System32\MSCOMCTL.OCX).

    • This does not really work for the following reasons:

      1. When Excel 2003 32-bit opens the sheet and it cannot find the reference to MSCOMCTL, it removes all the controls that came from the library (e. g. TreeCtrl) from the forms :-(
      2. Client is struggling with the procedure and it is quite cumbersome for him.

  2. Automatically correct the reference using VBA's VBProject.References.AddFromFile/AddFromGuid.
    • Same problem as above: When compilation of VBA during opening of workbook fails, Excel will remove all controls that it could not find from the forms.
  3. Automatically add the reference (as in 2.) and use dynamic binding to add all the relevant controls during runtime.
    • This could actually work, however currently I am struggling with binding the event handlers to the controls (but that will be separate question ;-)

Approaches 1. and 2. do not really solve anything and solution 3 is a lot of work.

Any ideas would be greatly appreciated.

解决方案

What if you automatically turned the reference off when the workbook closed? that way the reference wouldn't be 'broken' when the workbook is opened, and all your control should still be good.

i.e. :

Private Sub Workbook_Open()
'use environ variable for folder locs
If os = "64bit" Then
    Me.VBProject.References.AddFromFile ("C:\WINDOWS\SysWOW64\MSCOMCTL.OCX")
Else
    Me.VBProject.References.AddFromFile ("C:\WINDOWS\system32\MSCOMCTL.OCX")
End If
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    For Each ref In Me.VBProject.References
       If ref.Name = "MSComctlLib" Then
        Me.VBProject.References.Remove ref
       End If
        Next ref
End Sub

I did a quick test with the ADODB dll and it seemed to work,but I am not sure how you're using that DLL specifically; let me know if that works, though! Sure a lot better than option 3!

这篇关于Excel 2003在64位Windows 7会自动更改参考Syswow64资料\ MSCOMCTL.OCX所以32位Excel的抱怨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆