Share via


Workbooks.OpenDatabase Method

Excel Developer Reference

Returns a Workbook object representing a database.

Syntax

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

expression   A variable that represents a Workbooks object.

Parameters

Name Required/Optional Data Type Description
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.

Return Value
Workbook

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.

Visual Basic for Applications
  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

See Also