透過ADO存取xls檔案的方法

  • 45253
  • 0
  • ADO
  • 2010-03-08

摘要:透過ADO存取xls檔案的方法

 

	Dim cn As Object 
    Set cn = CreateObject("ADODB.Connection") 
    With cn 
        .Provider = "Microsoft.Jet.OLEDB.4.0" 
        .ConnectionString = "Data Source=D:\BACKUP\28F95.xls;Extended Properties=Excel 8.0;" 
        .Open 
    End With 
     
    Dim SQLTXT As String 
 
    'AAA代表工作表名稱 
    SQLTXT = "SELECT * FROM [AAA$] WHERE ([廠商代碼]=B0006)" 
     
    Dim rs As Object 
    Set rs = CreateObject("ADODB.RecordSet") 
    With rs 
        .CursorLocation = adUseClientBatch 
        .CursorType = adOpenDynamic 
        .LockType = adLockOptimistic 
        .ActiveConnection = cn 
    End With

以下是簽名:


Microsoft MVP
Visual Studio and Development Technologies
(2005~2019/6) 
topcat
Blog:http://www.dotblogs.com.tw/topcat