Workbooks.OpenDatabase method (Excel)
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 that contains the location and file name 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 that a file called Northwind.mdb 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
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.