Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Workbooks.OpenDatabase Method

Office 2007
Returns a Workbook object representing a database.


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

expression   A variable that represents a Workbooks object.


NameRequired/OptionalData TypeDescription
FilenameRequiredStringThe connection string which contains the location and filename of the database.
CommandTextOptionalVariantThe command text of the query.
CommandTypeOptionalVariantThe command type of the query. Specify one of the constants of the XlCmdType enumeration: xlCmdCube, xlCmdList, xlCmdSql, xlCmdTable, and xlCmdDefault.
BackgroundQueryOptionalVariantThis 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.
ImportDataAsOptionalVariantThis 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.

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

Community Additions

© 2015 Microsoft