Excel 2003 on 64-bit Windows 7 automatically changes reference to SysWOW64\\MSCOMCTL.OCX so 32-bit Excel complains

泄露秘密 提交于 2019-12-05 21:28:11

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!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!