|
本帖最后由 zww3008 于 2013-4-3 11:35 编辑
我试过以下方法,现在才搞清楚,由于不是MSCOMCTL.OCX文件真的损坏或丢失,只是因旧版本不匹配。导致对控件MSComctlLib的操作,无法识别,不能识别,也就没有对象,也就不能进行引用删除、引用添加等等操作!
原来是我把问题搞复杂了,只需更新MSCOMCTL.OCX文件并注册即可。不过从中也学到不少知识。我把MSCOMCTL.OCX剪切到其他目录,mdb会自动满世界地找到他{:soso_e113:}自动重新建立引用。
真正是由于MSCOMCTL.OCX版本引起的错误时,以下代码无效,但还是共享一下:
==================================
Private Sub Cmd查看_Click()
On Error Resume Next
Dim r As Reference
For Each r In References
' r.Name = "MSComctlLib"
MsgBox "类库名:" & r.Name & " GUID:" & r.Guid & " 版本" & r.Major & "." & r.Minor, , "信息"
' MsgBox "r.Guid:" & r.Guid
' MsgBox "类库名:" & r.Name & _
Chr(13) + Chr(13) + "类库文件绝对路径:" & r.FullPath & _
Chr(13) + Chr(13) + "是否内建:" & r.BuiltIn & _
Chr(13) + Chr(13) + "类库版本号Major=" & r.Major & " Minor=" & r.Minor & _
Chr(13) + Chr(13) + "r.Guid=" & r.Guid
Next
End Sub
Private Sub Cmd删除错误引用_Click()
Dim r As Reference
On Error Resume Next
'
For Each r In References
' If err = 48 Then
If r.IsBroken Then
Application.References.Remove r '如引用已损坏,删除
MsgBox r.Name & "引用已损坏,已被取消引用。", , ""
Else
MsgBox "未发现错误引用", , ""
Exit For
End If
' End If
Next
End Sub
Private Sub Cmd修复_Click()
On Error GoTo Err_Cmd修复_Click
'On Error Resume Next
Dim r As Reference
'首先检查CTL引用正常否
Dim bolFindAdo As Boolean
' 取消错误引用(方法一):
' For Each r In References
' If r.Name = "MSComctlLib" Or r.Guid = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}" Then
' If r.IsBroken Then
' MsgBox "引用已损坏,删除", , ""
' References.Remove r '如引用已损坏,删除
' Else
' bolFindAdo = True
' MsgBox "不需要修复!", , ""
' Exit For
' End If
' End If
' Next
' 取消错误引用(方法二):
Set r = Application.References!MSComctlLib
If r.IsBroken Then
Application.References.Remove r '如引用已损坏,删除
MsgBox r.Name & "引用已损坏,已被取消引用。", , ""
Else
bolFindAdo = True
MsgBox "不需要修复!", , ""
End If
'修复MSComctlLib引用
If bolFindAdo = False Then
MsgBox "还没引用,现在引用MSCOMCTL.OCX控件。"
Set r = Application.References.AddFromFile("c:\windows\system32\MSCOMCTL.OCX")
References.AddFromGuid _
Guid:="{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}", Major:=2, Minor:=1
' References.AddFromGuid _
Guid:="{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}"
End If
'下面重新搜索后确认
' For Each r In References
' If r.Name = "MSComctlLib" Or r.Guid = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}" Then
If r.IsBroken Then
MsgBox "引用失败!请检查是否存在文件C:\Windows\system32\MSCOMCTL.OCX", , ""
Else
If bolFindAdo = False Then MsgBox "修复MSCOMCTL.OCX的引用成功!", , ""
' bolFindAdo = True
' Exit For
End If
' End If
' Next
Exit_Cmd修复_Click:
Exit Sub
Err_Cmd修复_Click:
MsgBox err.Description & "加载失败,请联系管理员!", vbInformation, "提示"
Resume Exit_Cmd修复_Click
End Sub
|
|