Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QueryTables.Delete doesn't work for me

Status
Not open for further replies.

xml2

Programmer
Jul 18, 2003
20
BE
Hi,

I'm trying to import an externel .dat (plain text) file into an excel file. I recorded a macro whilest importing it via the menu, and afterwards edited it. But I noticed that after doing this for like 20 times the excell sheet was getting slower and slower (at the end it took 100% CPU load for about +/- 50sec)

This is the code I use:

With ActiveSheet.QueryTables.Add(Connection:="TEXT;Y:\Scan\OUT\OUT.DAT", _
Destination:=Range("A1"))
.Name = "out"
.FieldNames = True
.RowNumbers = False

.....

.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(3, 1, 1, 1, 1, 1, 1)
.Refresh BackgroundQuery:=False
End With

I searched the msdn to close the connections and tried this little peace of code:

For i = 1 To ActiveSheet.QueryTables.Count
ActiveSheet.QueryTables(i).Delete ' this is the line with the error
Next

but I get following error: (is normaly in dutch, but I'll try to translate it correct)

Fault 9 while executing:

The subscript is out of range
 
Try doing it backwards:
For i = ActiveSheet.QueryTables.Count to 1 step -1
ActiveSheet.QueryTables(i).Delete ' this is the line with the error
Next


Rgds, Geoff
Si hoc legere scis, nimis eruditionis habes
Want the best answers to your questions ? - then read me baby one more time - faq222-2244
 
Sorry to get this thread back up, but I wasn't working this weekend.

Just to say that this worked fine! Ty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top