View Full Version : Check an ActiveX control is installed
philfer
06-04-2011, 06:17 AM
Hi,
I am using a treeview control on a form and want to write a procedure so that any user using it on their pc can check if the control is installed first.
Is there a way to programmatically check if an ActiveX control is installed on the users PC?
Also is there a way to run RegSvr32 from VBA?
Thanks chaps
Phil
Kenneth Hobs
06-06-2011, 11:25 AM
You can use VBComponents to check and add.
'Andy Pope
'.VBProject.References.AddFromFile "D:\temp\ktMsgBoxAddin.xla"
'http://www.excelkb.com/article.aspx?id=10076&cNode=3M2R1E
Sub Add_External_Reference_()
'Must first add reference: Microsoft Visual Basic for Applications Extensibility 5.3 Library
Dim rVBReference As VBIDE.reference
Dim wbBook As Workbook
'The GUID to Microsoft Scripting Runtime.
Const stGuid As String = "{420B2830-E718-11CF-893D-00A0C9054228}"
Const stName As String = "MS Scripting Runtime"
Set wbBook = ThisWorkbook
On Error GoTo Error_Handling
With wbBook
'Iterate through the collection of active external references in the VB-project.
For Each rVBReference In .VBProject.references
If rVBReference.GUID = stGuid Then
MsgBox "The library of " & stName & " is already active!", vbInformation
GoTo ExitHere
End If
Next rVBReference
'Create the external reference in the VB-project.
.VBProject.references.AddFromGuid stGuid, 1, 0
MsgBox "The reference to " & stName & " is created!", vbInformation
GoTo ExitHere
End With
ExitHere:
Set rVBReference = Nothing
Exit Sub
Error_Handling:
MsgBox "Unable to create the reference as " & stName & vbCrLf _
& " is not available on this computer.", vbCritical
Resume ExitHere
End Sub
You can use Shell() to run RegSvr32.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.