Open Excel workbook using ADO 
Author Message
 Open Excel workbook using ADO

Hi There

What is the ADO connection string syntax if I want to open an Excel
workbook. If anyone has an example I would be grateful.

Greetings from Banstead, England



Wed, 18 Jun 1902 08:00:00 GMT  
 Open Excel workbook using ADO

Quote:

> What is the ADO connection string syntax if I want to open an Excel
> workbook. If anyone has an example I would be grateful.

  There's one approach on the list at at
http://www.able-consulting.com/ADO_Conn.htm
  Here's a different example:

'*******************************************
'* ADO to open Excel97 sheet as db/recordset *
'*******************************************
Dim cnnDB As adodb.Connection
Dim rsADO As adodb.Recordset
Dim strXLPath As String

Set cnnDB = New adodb.Connection
Set rsADO = New adodb.Recordset
strXLPath = "C:\SomeFolder\Your.xls"

' Specify Excel 8.0 by using the Extended Properties property,
' and then open the Excel file specified by strDBPath.
With cnnDB
   .Provider = "Microsoft.Jet.OLEDB.4.0"
   .Properties("Extended Properties") = "Excel 8.0"
   .Open strXLPath
End With

'open recordset from a worksheet - the name of the worksheet must be
'  placed in brackets with a dollar sign appended to sheet name.
With rsADO        
    ' use a lock type other than the default (adLockReadOnly) if you
    ' want to be able to update the recordset - activate next line
    '.LockType = adLockOptimistic

    ' Open the recordset with the SQL command you want
    .Open "SELECT * FROM [SomeSheet$] WHERE LastName = 'Doe'", _
          cnnDB, adOpenDynamic, , adCmdText
    'recordset is now open - perform any operations on it

    'when you're done:
    .Close
End With

--
Jim in Cleveland
If you're writing to me, in my address
change "REAL_Address.see.below" to "worldnet.att.net"
 ((("What's so funny 'bout peace, love & understanding?" - Nick Lowe)))



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Excel HRESULT: 0x800A03EC when using Workbooks.open or Workbooks._opentext in C#

2. How can I open Excel workbook without using Excel.Worksheet

3. Excel 97/2000: making custom functions (in a hidden workbook) available to all open workbooks

4. ASP using a VB DLL to open an Excel workbook

5. Excel Workbook takes too long to open in Excel 2000

6. Finding open Excel workbooks from Access.

7. Open Excel workbook

8. read/write without open workbooks in excel

9. Opening a Excel Workbook

10. Error handling when opening a workbook (Excel)

11. Populating a ListBox via a VBA macro when opening an Excel Workbook

12. Excel crashes during Workbooks.Open AND if the screen saver is active

 

 
Powered by phpBB® Forum Software