NatetheGreat
Active Member
- Joined
- Nov 18, 2013
- Messages
- 268
Hi there,
I am experimenting with opening files in excel.
Currently I am aware of and testing two approaches. the first is as follows via a dbconnection to the file without actually opening it.
Wrapping a timer around the dbconnection.open dbconnection string line, gave me a time of 7 seconds.
Alternatively is the following second approach, whereby I Use workbooks.open method
Suprisingly, this approach only took 4 seconds to open the same .xlsx file of 10.9MB. 3 seconds less than the database connection method.
Is anyone aware of a faster way to gain access to a files data? I am extracting from hundreds of files so every second counts!!
Thanks
Nate
I am experimenting with opening files in excel.
Currently I am aware of and testing two approaches. the first is as follows via a dbconnection to the file without actually opening it.
Code:
Sub GetDataFromClosedWorkbook(SourceFile As String, SourceRange As String, _
TargetRange As Range, IncludeFieldNames As Boolean)
Dim dbConnection As Object, rs As Object
Set dbConnection = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
'Dim dbConnection As ADODB.Connection, rs As ADODB.Recordset
Dim dbConnectionString As String
Dim TargetCell As Range, I As Long
dbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Mode=1;Data Source=" & SourceFile & ";Extended Properties=Excel 12.0;"
'Set dbConnection = New ADODB.Connection
dbConnection.Open dbConnectionString
Wrapping a timer around the dbconnection.open dbconnection string line, gave me a time of 7 seconds.
Alternatively is the following second approach, whereby I Use workbooks.open method
Code:
For Each myFile In fso.GetFolder(myDir).Files
Workbooks.Open (myDir & "\" & myFile.Name)
myCounter = myCounter + 1
ReDim Preserve myList(1 To myCounter)
myList(myCounter) = myDir & "\" & myFile.Name
Suprisingly, this approach only took 4 seconds to open the same .xlsx file of 10.9MB. 3 seconds less than the database connection method.
Is anyone aware of a faster way to gain access to a files data? I am extracting from hundreds of files so every second counts!!
Thanks
Nate