AddFromFile Method (References Collection)

Applies To

Reference object.

Description

The AddFromFile method creates a reference to a type library in a specified file.

Syntax

Set object = References.AddFromFile(filename)

The AddFromFile method has the following arguments.

Argument

Description

object

A Reference object.

filename

A string expression that evaluates to the full path and file name of the file containing the type library to which you wish to set a reference.


Remarks

The following table lists types of files that commonly contain type libraries.

File extension

Type of file

.olb, .tlb

Type library file

.mdb, .mda, .mde

Database

.exe, .dll

Executable file

.ocx

ActiveX control


See Also

AddFromGUID method, InsertLines method.

Example

The following example creates a reference to a specified type library:

Function ReferenceFromFile(strFileName As String) As Boolean
    Dim ref As Reference

    On Error GoTo Error_ReferenceFromFile
    ' Create new reference.
    Set ref = References.AddFromFile(strFileName)
    ReferenceFromFile = True

Exit_ReferenceFromFile:
    Exit Function

Error_ReferenceFromFile:
    MsgBox Err & ": " & Err.Description
    ReferenceFromFile = False
    Resume Exit_ReferenceFromFile
End Function
You could call this function by using a procedure such as the following, which creates a reference to the calendar control:

Sub CreateCalendarReference()
    If ReferenceFromFile("C:\Windows\System\Mscal.ocx") = True Then
        MsgBox "Reference to calendar control created successfully."
    Else
        MsgBox "Reference to calendar control not created successfully."
    End If
End Sub