''Chèn đoạn này vào Code có sử dụng thư viện
''Lưu ý ComctlLib có nhiều phiên bản nên Guid sẽ khác nhau, vì vậy khi phát triển phải Copy Guid của phiên bản đó với Sub GetReferencesGuid.
Sub ABC()
On Error GoTo Ends
If CheckLibrarySYS("MSComctlLib", "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}", 2, 0) = "" Then
VBA.err.Raise 11111, , "MISSING: Library MSComctlLib"
End If
''------------------------
''Code có sử dụng thư viện ở đây
''------------------------
Ends:
End Sub
''Copy đoạn code dưới vào một Public Module
Public Function CheckLibrarySYS(LibraryName As String, _
GuidAdd As String, _
Major As Long, _
Minor As Long, _
Optional ByVal VBProject As Object) As String
On Error Resume Next
If VBProject Is Nothing Then Set VBProject = ThisWorkbook.VBProject
GoSub Lib
ThisWorkbook.VBProject.References.AddFromGuid GuidAdd, Major, Minor
GoSub Lib
Exit Function
Lib:
Dim Ref As Object ''Reference
For Each Ref In ThisWorkbook.VBProject.References
With Ref
If VBA.LCase(.Name) = VBA.LCase(LibraryName) Then
CheckLibrarySYS = .FullPath: Exit Function
End If
End With
Next Ref
On Error GoTo 0
Return
End Function
Sub GetReferencesGuid()
Dim Ref As Object
For Each Ref In ThisWorkbook.VBProject.References
With Ref
If .GUID <> "" Then _
Debug.Print ".AddFromGuid "; """" & .GUID & """"; ",Major:=" & .Major; ",Minor:=" & .Minor; "'"; .Name, .FullPath
End With
Next Ref
Application.VBE.Windows("Immediate").Visible = True
End Sub