View Full Version : Check an ActiveX control is installed

06-04-2011, 06:17 AM

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

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"

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

Set rVBReference = Nothing
Exit Sub

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.