|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 算命先生kaven 于 2017-2-23 15:30 编辑
我根据这段代码做了个小小的修改,想解决丢失Microsoft Windows Common Controls 6.0 (SP6)的问题,但好象没有效果。代码运行是没有问题的,我试过,但运行后还是丢失。
下面是我修改的代码:
Private Sub aas()
'遍历所有已使用的引用
Dim g As Integer
Dim Ref()
g = 1
Set refed = ThisWorkbook.VBProject.References
ReDim Ref(refed.Count, 4)
For f = 1 To refed.Count
With refed.Item(f)
Ref(f - 1, 1) = .Name
Sheet2.Cells(f, 1) = Ref(f - 1, 1)
Ref(f - 1, 2) = .GUID
Sheet2.Cells(f, 2) = Ref(f - 1, 2)
Ref(f - 1, 3) = .Major
Sheet2.Cells(f, 3) = Ref(f - 1, 3)
Ref(f - 1, 4) = .Minor
Sheet2.Cells(f, 4) = Ref(f - 1, 4)
End With
'f = f + 1
Next
For g = refed.Count To 1 Step -1
Set theRef = refed.Item(g)
If theRef.IsBroken = True Then
refed.Remove theRef
End If
Next g
Err.Clear
Dim errmsg As String
For g = 0 To f - 1
refed.AddFromGuid GUID:=Ref(g, 2), Major:=Ref(g, 3), Minor:=Ref(g, 4)
Select Case Err.Number
Case Is = 32813
'引用已经加载,无需做任何事情
Case Is = vbNullString
'成功加载
Case Else
'加载出现错误,保存错误信息
errmsg = errmsg & Ref(g, 0) & "出现错误错误"
End Select
Next g
If errmsg <> "" Then
MsgBox errmsg
End If
On Error GoTo 0
Exit Sub
ERRHandle:
MsgBox (Err.Description & "加载失败,请联系管理员!")
End Sub
请高手指点一二,不胜感激。 |
-
|