Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ommit</p> <p>There are two ways to add references via VBA to your projects</p> <p><strong>1)</strong> Using GUID</p> <p><strong>2)</strong> Directly referencing the dll.</p> <p>Let me cover both.</p> <p>But first these are 3 things you need to take care of</p> <p><strong>a)</strong> Macros should be enabled</p> <p><strong>b)</strong> In Security settings, ensure that "Trust Access To Visual Basic Project" is checked</p> <p><img src="https://i.stack.imgur.com/Map0m.jpg" alt="enter image description here"></p> <p><strong>c)</strong> You have manually set a reference to `Microsoft Visual Basic for Applications Extensibility" object</p> <p><img src="https://i.stack.imgur.com/UHJDa.png" alt="enter image description here"></p> <p><strong>Way 1 (Using GUID)</strong></p> <p>I usually avoid this way as I have to search for the GUID in the registry... which I hate LOL. More on GUID <a href="http://en.wikipedia.org/wiki/GUID" rel="noreferrer">here</a>.</p> <p><strong>Topic: Add a VBA Reference Library via code</strong> </p> <p><strong>Link</strong>: <a href="http://www.vbaexpress.com/kb/getarticle.php?kb_id=267" rel="noreferrer">http://www.vbaexpress.com/kb/getarticle.php?kb_id=267</a></p> <hr> <p><strong>Way 2 (Directly referencing the dll)</strong></p> <p>This code adds a reference to <code>Microsoft VBScript Regular Expressions 5.5</code></p> <pre><code>Option Explicit Sub AddReference() Dim VBAEditor As VBIDE.VBE Dim vbProj As VBIDE.VBProject Dim chkRef As VBIDE.Reference Dim BoolExists As Boolean Set VBAEditor = Application.VBE Set vbProj = ActiveWorkbook.VBProject '~~&gt; Check if "Microsoft VBScript Regular Expressions 5.5" is already added For Each chkRef In vbProj.References If chkRef.Name = "VBScript_RegExp_55" Then BoolExists = True GoTo CleanUp End If Next vbProj.References.AddFromFile "C:\WINDOWS\system32\vbscript.dll\3" CleanUp: If BoolExists = True Then MsgBox "Reference already exists" Else MsgBox "Reference Added Successfully" End If Set vbProj = Nothing Set VBAEditor = Nothing End Sub </code></pre> <p><strong>Note</strong>: I have not added Error Handling. It is recommended that in your actual code, do use it :)</p> <p><strong>EDIT</strong> Beaten by <code>mischab1</code> :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload