Module.AddFromFile method (Access)

The AddFromFile method adds the contents of a text file to a Module object. The Module object may represent a standard module or a class module.

Syntax

expression.AddFromFile (FileName)

expression A variable that represents a Module object.

Parameters

Name Required/Optional Data type Description
FileName Required String The name and full path of a text (.txt) file or another file that stores text in an ANSI format.

Remarks

The AddFromFile method places the contents of the specified text file immediately after the Declarations section and before the first procedure in the module if it contains other procedures.

The AddFromFile method enables you to import code or comments stored in a text file.

To add the contents of a file to a form or report module, the form or report must be open in form Design view or report Design view. To add the contents of a file to a standard module or class module, the module must be open.

Example

The following example places the contents of the file "ShippingRoutines.bas" into the module "CalculateShipping" immediately after the Declarations section, but before the first procedure in the module.

Modules("CalculateShipping").AddFromFile "C:\Shipping\ShippingRoutines.bas" 

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.