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: 22
Default querytable connection

Excel help files for version 2002 give the following example:

This example imports a fixed-width text file into a new query table on the first worksheet in the first workbook. The first column in the text file is five characters wide and is imported as text. The second column is four characters wide and is skipped. The remainder of the text file is imported into the third column and has the General format applied to it.




Set shFirstQtr = Workbooks(1).Worksheets(1)
Set qtQtrResults = shFirstQtr.QueryTables _
.Add(Connection := "TEXT;C:\My Documents\19980331.txt", _
Destination := shFirstQtr.Cells(1, 1))
With qtQtrResults
.TextFileParseType = xlFixedWidth
.TextFileFixedColumnWidths = Array(5, 4)
.TextFileColumnDataTypes = _
Array(xlTextFormat, xlSkipColumn, xlGeneralFormat)
.Refresh
End With


I have tried modifying the file path to be automatically set as the the
current path (thisworkbook.path) etc. without success.

Ideally I would like to set the above up as a called process for all
equiv?.txt files in the current directory (where ? equals 1 to 5).

Alternately,

The following portion of code courtesy John Walkenbach's Excel 2000 power
programming imports and parses multiple text files (do while loops not shown
here) with the opentext command, however these are all opened into separate
files rather than one single file:

Workbooks.OpenText FileName:=FileName, _
Origin:=xlWindows, _
StartRow:=1, _
DataType:=xlFixedWidth, _
FieldInfo:= _
Array(Array(0, 1), Array(3, 1), Array(12, 1))

The above would be perfect if modified to import to multiple sheets (with
same names as originating text file) within a single excel file.

Thanks for any help.

Jason
 
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
always recheck data connection library for latest connection strin FurmanGG Excel Discussion (Misc queries) 0 September 14th 07 04:48 PM
QueryTable OLE DB with Parameter Rob van Gelder[_4_] Excel Programming 0 December 12th 04 03:15 AM
Find the contents of a Connection property of the QueryTable objec SPYREN Excel Programming 4 October 28th 04 04:03 PM
Bad QueryTable Row Count igneramos[_3_] Excel Programming 0 January 27th 04 10:21 PM
Querytable Ben.c Excel Programming 4 December 3rd 03 09:11 AM


All times are GMT +1. The time now is 08:33 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"