Hi,
I'm running a looping process from an Access module to find values in a series of Excel Workbooks. The workbooks are typically small, averaging around 3-5000 rows of data across 10 columns. I'm copying the files to my C:\ drive to process them. Simplified:
The find operation itself is ridiculously slow, each is taking around 10 seconds to return a value. I can manually return a result pretty much instantaneously, as I can from the Excel VBE. It's just from Access I'm having the problem.
I'd wondered if it has something to do with already having the book open and using GetObject, so I ran the find operation direct in the main routine. This didn't improve things.
Here's the code:
Any advice would be appreciated, I'm running Excel & Access 2000 on Win 2k.
Cheers, Iain
I'm running a looping process from an Access module to find values in a series of Excel Workbooks. The workbooks are typically small, averaging around 3-5000 rows of data across 10 columns. I'm copying the files to my C:\ drive to process them. Simplified:
Code:
'Check each file in the list
Do Until rstFiles.EOF
appXL.Workbooks.Open rstFiles("FilePath")
'Copy file to C:\ here
'Look for all the values I want to find
Do Until rstValues.EOF
call Excel_Find(rstValues("ValueToFind"), "C:\FileToProcess")
rstValues.MoveNext
Loop
appXL.Workbooks.Close
rstFiles.MoveNext
Loop
The find operation itself is ridiculously slow, each is taking around 10 seconds to return a value. I can manually return a result pretty much instantaneously, as I can from the Excel VBE. It's just from Access I'm having the problem.
I'd wondered if it has something to do with already having the book open and using GetObject, so I ran the find operation direct in the main routine. This didn't improve things.
Here's the code:
Code:
Public Function Excel_Find(strWhat As String, strFileName As String) As Integer
'Find instances of strWhat in workbook strFileName
Dim c As Range
Dim strFirstAddress As String
Dim i As Integer
Dim appXL As Object
'Workbook will already be open, so just grab its window
Set appXL = GetObject(, "Excel.Application")
'No need for system messages
appXL.DisplayAlerts = False
'Initialise the counters
i = 0
'Select all worksheets so we only have to search once
appXL.ActiveWorkbook.Worksheets.Select
'------------------------------
'Have we found the search term?
'------------------------------
[COLOR=blue]Set c = appXL.Cells.Find(what:=strWhat, LookIn:=xlValues, lookat:=xlWhole)[/color blue]
'EXTREMELY SLOW FROM ABOVE TO NEXT
If Not c Is Nothing Then 'yes we have
Debug.Print strWhat
'Increase the counter
i = i + 1
'Set the first found cell to avoid an endless loop
strFirstAddress = c.Address
'------------------------------------------------------------
'Loop through the sheet, looking for further unique instances
'------------------------------------------------------------
Do
'Find the next instance
Set c = appXL.Cells.FindNext(c)
'Increase the counter
i = i + 1
Loop While Not (c.Address = strFirstAddress Or i > 2)
End If
Excel_Find = i
Set appXL = Nothing
i = Empty
strWhat = Empty
strFileName = Empty
strFirstAddress = Empty
End Function
Any advice would be appreciated, I'm running Excel & Access 2000 on Win 2k.
Cheers, Iain