Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default File disconnect with QueryTable

Im importing a string of text and Im using the only method that I know
which is with a QueryTable, as shown below. If theres a better and easier
way, please let me know.

Application.Goto Reference:="ReceivingCell"

With Selection.QueryTable
.Connection = "TEXT;C:\Source.txt"
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierNone
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=True
End With

Im experiencing two problems. The biggest problem is that periodically it
loses the connection, for some reason that I dont understand, and its not
easy to reconnect it. That disconnect also happens every time I make a copy
of the WorkBook. The other problem is that from time to time the source file
is blank. I really dont understand that. Of course its just test data at
this time, but still I have to recreate it every time. Is it mandatory that
there be a constant link?

TomD

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default File disconnect with QueryTable

there are several ways. In my oipinion, if you just want to read simple data,
then use the "OPEN" method

here's some example code:

Option Explicit

Sub FetchData()

Dim ch As Long ' assign channel for the OPEN command
Dim sFileName As String '
Dim text As String
Dim rowindex As Long

sFileName = "C:/Temp/Source.txt"
ch = FreeFile

Open sFileName For Input As ch
Do Until EOF(ch)
Input #ch, text
rowindex = rowindex + 1
Cells(rowindex, 1) = text

Loop

Close ch


End Sub



"TomD" wrote:

Im importing a string of text and Im using the only method that I know
which is with a QueryTable, as shown below. If theres a better and easier
way, please let me know.

Application.Goto Reference:="ReceivingCell"

With Selection.QueryTable
.Connection = "TEXT;C:\Source.txt"
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierNone
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=True
End With

Im experiencing two problems. The biggest problem is that periodically it
loses the connection, for some reason that I dont understand, and its not
easy to reconnect it. That disconnect also happens every time I make a copy
of the WorkBook. The other problem is that from time to time the source file
is blank. I really dont understand that. Of course its just test data at
this time, but still I have to recreate it every time. Is it mandatory that
there be a constant link?

TomD

Reply
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
Reset QueryTable error on empty text file RK Henry Excel Programming 1 December 8th 09 05:46 PM
Browse 4 a file & disconnect a connection to external source Faraz A. Qureshi Excel Programming 1 September 14th 09 08:48 PM
Disconnect linked file SLP Excel Discussion (Misc queries) 3 July 5th 07 02:40 PM
Changing only source file of pre-existing text import QueryTable? EBrowne Excel Programming 3 August 23rd 04 03:31 AM


All times are GMT +1. The time now is 12:05 PM.

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

About Us

"It's about Microsoft Excel"