OpenDatabase Method [Excel 2003 VBA Language Reference]

Returns a Workbook object representing a database.

expression.OpenDatabase(FileName, CommandText, CommandType, BackgroundQuery, ImportDataAs)

expression Required. An expression that returns one of the objects in the Applies To list.

FileName  Required String. The connection string which contains the location and filename of the database.

CommandText  Optional Variant. The command text of the query.

CommandType  Optional Variant. The command type of the query. Specify one of the constants of the xlCmdType enumeration: xlCmdCube, xlCmdList, xlCmdSql, xlCmdTable, and xlCmdDefault.

BackgroundQuery  Optional Variant. This parameter is a variant data type but you can only pass a Boolean value. If you pass True, the query is performed in the background (asynchronously). The default value is False.

ImportDataAs  Optional Variant. This parameter uses one of the values of the XlImportDataAs enumeration. The two values of this enum are xlPivotTableReport and xlQueryTable. Pass one of these values to return the data as a PivotTable or QueryTable. The default value is xlQueryTable.

Example

In this example, Microsoft Excel opens the "northwind.mdb" file. This example assumes a file called "northwind.mdb file" exists on the C:\ drive.

Sub UseOpenDatabase()
    ' Open the Northwind database in the background and create a PivotTable
    Workbooks.OpenDatabase Filename:="c:\Northwind.mdb", _
        CommandText:="Orders", _
        CommandType:=xlCmdTable, _
        BackgroundQuery:=True, _
        ImportDataAs:=xlPivotTableReport
End Sub

Applies to | Workbooks Collection