+ Reply to Thread
Results 1 to 9 of 9

QueryTable.connection FoundFiles(i) can not load

  1. #1
    Registered User
    Join Date
    06-28-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2003
    Posts
    6

    QueryTable.connection FoundFiles(i) can not load

    Hi there,
    I have a series of .txt files that need to be imported in order and processed in EXCEL. I'm trying to sort it first and then processed one by one.
    The problem is when I'm using .Foundfiles(i) in the QueryTable. connection to indicate the path, it pops up the window to let you select the file, where I thought it should directly load the current .FoundFiles(i) file.
    Here is part of the file. Any help would be greatly appreciated!


    Set fs = Application.FileSearch
    With fs
    .LookIn = "C:\Documents and Settings\mx1000\Desktop\VBA"
    .Filename = "*.txt"
    If .Execute(SortBy:=msoSortByFileName, _
    SortOrder:=msoSortOrderAscending) > 0 Then
    MsgBox "There were " & .FoundFiles.Count & _
    " file(s) found."
    For i = 1 To .FoundFiles.Count
    MsgBox .FoundFiles(i)
    'fsort(i) = .FoundFiles(i)
    'import data
    Sheets("Row data").Select
    Range("A1").Select
    With Selection.QueryTable
    .Connection = "TEXT;C:\Documents and Settings\mx1000\Desktop\VBA\.FoundFiles(i)"
    .TextFilePlatform = 437
    .TextFileStartRow = 1
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = True
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = False
    .TextFileSpaceDelimiter = False
    .TextFileColumnDataTypes = Array(1, 1)
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False
    End With
    ........

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: QueryTable.connection FoundFiles(i) can not load

    Cross posted here:

    http://www.mrexcel.com/forum/showthread.php?t=477604

    Melody44 please take a moment to read this: http://www.excelguru.ca/node/7

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: QueryTable.connection FoundFiles(i) can not load

    I'm guessing this might fix it:

    Please Login or Register  to view this content.

    Dom

  4. #4
    Registered User
    Join Date
    06-28-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: QueryTable.connection FoundFiles(i) can not load

    Quote Originally Posted by Domski View Post
    I'm guessing this might fix it:

    Please Login or Register  to view this content.

    Dom
    Hi Dom,
    Thank you for your quick reply. But it doesn't work. It stoped on this sentence and asked for debug. Is there other possibilities?

    Thanks

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: QueryTable.connection FoundFiles(i) can not load

    It should be:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: QueryTable.connection FoundFiles(i) can not load

    I think the whole thing should be more like this:

    Please Login or Register  to view this content.

    Dom

  7. #7
    Registered User
    Join Date
    06-28-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: QueryTable.connection FoundFiles(i) can not load

    Quote Originally Posted by Domski View Post
    I think the whole thing should be more like this:

    Please Login or Register  to view this content.

    Dom
    Thanks so much. I will give a try and get back to you. Appreciate it!

  8. #8
    Registered User
    Join Date
    06-28-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: QueryTable.connection FoundFiles(i) can not load

    Thanks Dom,
    That works! I added to your reputation. Many Thanks!

  9. #9
    Registered User
    Join Date
    06-28-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: QueryTable.connection FoundFiles(i) can not load

    One more question: it still pop up a selection table each time with the selected FoundFiles(i). Then I need to click "import" to load each file. Is there anyway It can just run through all the files without click each time?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1