LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Code with query goes from greyhound to turtle speed

I have a macro which calls the Sub below 17,000+ times to get data from an
equal number of small files. The macro always starts out running very
fast, but quickly slows to a snail's pace. The only way I have found to
speed it up again is to stop the macro, save the file and close Excel, then
restart Excel, reload the worksheet and have it pick up where it left off.

Clearly some resource is being used up and not released between calls to
the Sub. Perhaps I endup with a myriad of open files??

Any help in resolving this issue would be much appreciated. Thanks.

Here is the Sub:

Sub GetParcelInfoFromFile(Parcel As String)
Dim FileName As String
Dim qt As QueryTable

On Error GoTo NoQT 'Try to speed this up by deleting quries
For Each qt In Worksheets("Temp").QueryTables
qt.Delete
Next qt

NoQT:
On Error GoTo 0
'Build name of file containing data
FileName = "F:\IOW Harvest Data\" & Left(Parcel, 1) & "\" & Parcel &
".txt"

If Len(Dir(FileName)) = 0 Then 'If file does not exist
Range("Temp!A1") = "No File"
Exit Sub
End If
Worksheets("Temp").Select 'Get data into this sheet
With Worksheets("Temp").QueryTables.Add(Connection:="TE XT;" & FileName,
Destination:=Range("A1"))
.Name = Parcel
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1)
.Refresh BackgroundQuery:=False
End With
Worksheets(Orig).Select
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to Speed Up A Code LostInNY Excel Worksheet Functions 2 July 20th 09 06:18 PM
Running speed of Micrsoft Query with Multiple parameters Ken Excel Discussion (Misc queries) 1 March 19th 07 11:21 PM
Speed up code Derick Hughes Excel Programming 0 February 8th 05 04:18 PM
How can I Improve query speed? John[_60_] Excel Programming 5 October 12th 04 01:00 PM
Macros go slower than a turtle in mud BOHICA Excel Programming 2 March 6th 04 06:41 PM


All times are GMT +1. The time now is 10:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"