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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem importing text file into Excel.

Status
Not open for further replies.

bdbBear

Programmer
Apr 29, 2005
54
US
The following code brings in data from a text file. It's supposed to just paste the data in the destination range. For some reason it's inserting columns (on some user's computers - right now users are using XP and XL03). Any idea what could be causing the columns to be inserted?

With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & Filename, Destination:=Range("B8"))
.FieldNames = True
.PreserveFormatting = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = False
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTabDelimiter = True
.Refresh BackgroundQuery:=False
End With
 
Hi,

1. When you ADD a QueryTable it INSERTS columns based on the number of columns in the QueryTable.

2. You only need to ADD a QueryTable ONE TIME. You should NOT use the recorded code repeatedly for the same Import. Rather you should use Data/Refresh Data[/t]. Using code you can reference the QueryTable NAME as such...
Code:
[MyQueryTableName].QueryTable.RefreshData


Skip,
[sub]
[glasses] [red]Be Advised![/red] The Vinyards of Texas have produced a wine with diuretic dimishment and urethric relief...
Pinot More![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top