I had the following function that auto add Microsoft Script Runtime
Reference to the Reference list. However, if the user already had included Microsoft script runtime
, it will show error Name conflicts with existing module,project, object library
.
How do I set an condition that auto adds Microsoft script runtime
if it is not included in the reference and do nothing if it has already being added?
Private Function AddScriptingLibrary() As Boolean
Const GUID As String = "{420B2830-E718-11CF-893D-00A0C9054228}"
On Error GoTo errHandler
ThisWorkbook.VBProject.References.AddFromGuid GUID, 1, 0
AddScriptingLibrary = True
Exit Function
errHandler:
MsgBox Err.Description
End Function
You'll need to enumerate the references of the project first, in order to check if the reference is already present.
I've added a reference to Microsoft Visual Basic for Applications Extensibility 5.3
EDIT this does the same, but without the early-bound reference to Visual Basic For Applications Extensibility 5.3 reference:
But then, if you're happy with the down-sides of late-bound code, you don't even need the reference to
Scripting.Runtime
, because you can just use: