LockXLS On-line Help Library

Getting Started
Using LockXLS
How to ...
General Questions
Questions about LockXLS activation
Advanced Questions
LockXLS Runtime Menu
About LockXLS
Open locked document from external application using OLEDB/ODBC driver

Open locked document from external application using OLEDB/ODBC driver.

You can open locked file using OLEDB and ODBC. You should use same code as you are using for usual Excel workbook. But, it must be placed between the following statements:

' declare variable for LockXLS Runtime object
Dim oLockXLS As Object
' get Runtime Object from Excel application
Set oLockXLS = CreateObject( "LockXLSRuntime.Connect" );
' enable access for ODBC driver
Call oLockXLS.EnableODBCAccess( True )
' open locked workbook using OLEDB/ODBC
Dim oConnection As ADODB.Connection
Dim oRS As ADODB.Recordset

Set oConnection = New ADODB.Connection

oConnection.Provider = "Microsoft.Jet.OLEDB.4.0"
oConnection.ConnectionString = _
  "Data Source=" & ActiveDocument.Path & "\Source.xls;" & _
  "Extended Properties=Excel 8.0;"


Set oRS = New ADODB.Recordset

oRS.Open "Select * from [Sheet1$]", oConnection

While Not oRS.EOF


' disable access for ODBC driver this call is required
Call oLockXLS.EnableODBCAccess( False )
' release LockXLS Runtime object
Set oLockXLS = Nothing

See Also:
LockXLS Runtime Object members