Check to see if reference library is enabled

  • Thread starter Thread starter PJ
  • Start date Start date
P

PJ

I was given a macro that requires "Microsoft Scripting Runtime" be enabled in
order to work properly. Is there a way I can add a check to see if the user
running the macro has it enabled? I want to add a prompt with instructions
if they do not but I need to know how to verify first.
 
Private Sub AddRefToScripting()
'______________________________________________
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
'Di Roberto Mensa nick r
'______________________________________________
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
'controlla i riferimenti
'se manca il riferimento a Scripting lo aggiunge

With Application.VBE
If Verifica_Riferimento(.ActiveVBProject, "Scripting") = False Then
.ActiveVBProject.References.AddFromGuid _
"{420B2830-E718-11CF-893D-00A0C9054228}", 1, 0
End If
End With
End Sub

Public Function Verifica_Riferimento( _
ByRef oProject As Object, _
ByVal sRef As String) As Boolean
'______________________________________________
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
'Di Roberto Mensa nick r
'______________________________________________
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
'Verifica se un riferimento è caricato su
'oProject
'sRef il nome del riferimento nel codice
Dim v
For Each v In oProject.References
If UCase(v.Name) = UCase(sRef) Then
Verifica_Riferimento = True
Exit Function
End If
Next
End Function

regards
r

Il mio ultimo lavoro ...
http://excelvba.altervista.org/blog/index.php/Excel-VBA/UsedRange-eccezioni-e-alternative.html
 
I wouldn't do this. Instead have the author of the macro (or you???) change it
so that you use late binding instead of early binding.

Some references:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;244167
INFO: Writing Automation Clients for Multiple Office Versions

http://support.microsoft.com/default.aspx?scid=kb;en-us;245115
INFO: Using Early Binding and Late Binding in Automation

http://support.microsoft.com/default.aspx?scid=kb;en-us;247579
INFO: Use DISPID Binding to Automate Office Applications Whenever Possible

and Dick Kusleika has a web page at:
http://www.dicks-clicks.com/excel/olBinding.htm
that explains this with Outlook

==========
I'd develop with the references so that I could get the benefit of the
intellisense and autocomplete within the VBE, but then change to late binding
before sharing with others.
 
Place a check within the loop...

Dim ref As Variant
For Each ref In Application.VBE.ActiveVBProject.References
MsgBox ref.Name
Next

If this post helps click Yes
 
Back
Top