Excel vba set up new reference

To set up a new reference in Excel VBA, you can follow these steps:

  1. Open the Visual Basic Editor (VBE) by pressing Alt + F11 or by navigating to Developer > Visual Basic in the ribbon.
  2. In the VBE, click on Tools > References in the menu.
  3. In the References dialog box, check the box next to the library or object model you want to reference. For example, if you want to reference the Microsoft Office 16.0 Object Library, check the box next to it.
  4. Click OK to close the References dialog box.

Alternatively, you can also set up a new reference by using the Tools > References command in the VBE and then selecting the library or object model you want to reference from the list.

Here are some common references that you may need to set up in Excel VBA:

Note that the exact name of the reference may vary depending on the version of Excel and the library or object model you are trying to reference.

Also, you can use the VBAProject object to set up a reference programmatically. For example:

Sub SetReference()
    Dim vbaProject As VBAProject
    Set vbaProject = ThisWorkbook.VBAProject
    vbaProject.References.Add "Microsoft Office 16.0 Object Library"
End Sub

This code sets up a reference to the Microsoft Office 16.0 Object Library programmatically.