InsertFile Method

Applies To

Range object, Selection object.

Description

Inserts all or part of the specified file.

Syntax

expression.InsertFile(FileName, Range, ConfirmConversions, Link, Attachment)

expression Required. An expression that returns a Range or Selection object.

FileName Required String. The path and file name of the file to be inserted. If you don't specify a path, Word assumes the file is in the current folder.

Range Optional Variant. If the specified file is a Word document, this parameter refers to a bookmark. If the file is another type (for example, a Microsoft Excel worksheet), this parameter refers to a named range or a cell range (for example, R1C1:R3C4).

ConfirmConversions Optional Variant. True to have Word prompt you to confirm conversion when inserting files in formats other than the Word Document format.

Link Optional Variant. True to insert the file by using an INCLUDETEXT field.

Attachment Optional Variant. True to insert the file as an attachment to a WordMail message.

See Also

Add method (Fields collection), InsertDatabase method.

Example

This example uses an INCLUDETEXT field to insert the Test.doc file at the insertion point.

Selection.Collapse Direction:=wdCollapseEnd
Selection.InsertFile FileName:="C:\Test.doc", Link:=True
This example creates a new document and then inserts the contents of each text file in the C:\Tmp folder into the new document.

Documents.Add
ChDir "C:\Tmp"
myName = Dir("*.txt")
While myName <> ""
    With Selection
        .InsertFile FileName:=myName, ConfirmConversions:=False
        .InsertParagraphAfter
        .InsertBreak Type:=wdSectionBreakNextPage
        .Collapse Direction:=wdCollapseEnd
    End With
    myName = Dir()
Wend