简体   繁体   English

VBA-ADODB.Connection从Excel读取

[英]VBA - ADODB.Connection to read from Excel

Does using ADODB.Connection to read data from Excel files actually open the excel files? 使用ADODB.Connection从Excel文件读取数据是否实际上打开了excel文件?

Is there a performance benefit from using ADODB vs opening the file through VBA using GetObject() and reading the data (with screen updating = false)? 与使用GetObject()通过VBA打开文件并读取数据(屏幕更新= false)相比,使用ADODB相对于性能有好处吗?

GetObject() seems to sometime take a while to open the file depending on the file. 根据文件的不同,GetObject()似乎有时需要一段时间才能打开文件。 I would like a more "lightweight" alternative to pulling data from the excel file. 我想要从excel文件中提取数据的更“轻巧”的选择。

Unless you need the functionalities inherent to Excel, I would usually go with an ADO connection. 除非您需要Excel固有的功能,否则我通常会使用ADO连接。

Dim cn as ADODB.Connection
Set cn = New ADODB.Connection
With cn
    .Provider = "Microsoft.Jet.OLEDB.4.0"
    .ConnectionString = "Data Source=C:\MyFolder\MyWorkbook.xls;" & _
"Extended Properties=Excel 8.0;"
    .Open
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM