Range.InsertDatabase procedure builder

Range.InsertDatabase (Word)

Retrieves data from a data source (for example, a separate Microsoft Word document, a Microsoft Excel worksheet, or a Microsoft Access database) and inserts the data as a table in place of the specified range.

The value of the Style argument can be the sum of any combination of the following values:

InsertDatabase (Format, Style, LinkToSource, Connection, SQLStatement, SQLStatement1, PasswordDocument, PasswordTemplate, WritePasswordDocument, WritePasswordTemplate, DataSource, From, To, IncludeFields)

With Selection 
    .Collapse Direction:=wdCollapseEnd 
    .Range.InsertDatabase _ 
        Format:=wdTableFormatSimple2, Style:=191, _ 
        LinkToSource:=False, Connection:="Entire Spreadsheet", _ 
End With


Optional arguments

The following arguments are optional

Format (WdTableFormat) - A format listed in the Formats box in the Table AutoFormat dialog box (Table menu). Can be any of the WdTableFormat constants. A border is applied to the cells in the table by default.

Here you can find possible values for .


Style - The attributes of the AutoFormat specified by Format that are applied to the table

LinkToSource - True to establish a link between the new table and the data source

Connection (Range) - A range within which to perform the query specified by SQLStatement.

SQLStatement - An optional query string that retrieves a subset of the data in a primary data source to be inserted into the document

SQLStatement1 - If the query string is longer than 255 characters, SQLStatement denotes the first portion of the string and SQLStatement1 denotes the second portion

PasswordDocument - The password (if any) required to open the data source. (See Remarks below.)

PasswordTemplate - If the data source is a Word document, this argument is the password (if any) required to open the attached template. (See Remarks below.)

WritePasswordDocument - The password required to save changes to the document. (See Remarks below.)

WritePasswordTemplate - The password required to save changes to the template. (See Remarks below.)

DataSource - The path and file name of the data source

From - The number of the first record in the range of records to be inserted

To - The number of the last record in the range of records to be inserted

IncludeFields - True to include field names from the data source in the first row of the new table