Workbooks.OpenDatabase Method (Excel)

Returns a Workbook object representing a database.


expression. OpenDatabase( _Filename_ , _CommandText_ , _CommandType_ , _BackgroundQuery_ , _ImportDataAs_ )

expression A variable that represents a Workbooks object.


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



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, _ 
End Sub

See also

Workbooks Object