Results 1 to 8 of 8

method for importing .txt files into separate columns

Threaded View

microsofteggshell method for importing .txt... 02-11-2013, 03:12 PM
Alf Re: method for importing .txt... 02-11-2013, 05:58 PM
microsofteggshell Re: method for importing .txt... 02-12-2013, 08:34 AM
Alf Re: method for importing .txt... 02-12-2013, 09:13 AM
microsofteggshell Re: method for importing .txt... 02-12-2013, 10:34 AM
Alf Re: method for importing .txt... 02-12-2013, 12:39 PM
microsofteggshell Re: method for importing .txt... 02-14-2013, 06:53 AM
Alf Re: method for importing .txt... 02-14-2013, 09:36 AM
  1. #1
    Registered User
    Join Date
    02-11-2013
    Location
    Ireland
    MS-Off Ver
    Excel 2003
    Posts
    7

    method for importing .txt files into separate columns

    Hi, I have to import text files (example attached) manually into a spreadsheet and was looking for a simpler, less time consuming method of doing this. I came across some suggestions on this forum that gave me hope that there is a better way. However I don't know much about VBA and have so far being substituting my current macro into some of the suggested solutions posted here. I just cant seem to get it to fully do what I require which is:

    1)Take .txt files from a selected folder,
    2)Format using macro used for manually adding .txt files
    3)Add .txt files into existing spreadsheet into next free column.
    The .txt. files are sorted by date in the folder (oldest-newest) and this is the order which I enter them into the spreadsheet. The sheet gets updated weekly with about 20-30 files .txt each time.

    The macro I use when manually adding at the moment is:

    Sub test()
    '
    ' test Macro
    '
    
    '
        With ActiveSheet.QueryTables.Add(Connection:="TEXT;F:\129629_$01_121056.txt" _
            , Destination:=Range("$A$1"))
            .Name = "129629_$01_121056"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 850
            .TextFileStartRow = 1
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileOtherDelimiter = ":"
            .TextFileColumnDataTypes = Array(1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        ActiveWindow.SmallScroll Down:=-12
        Application.Goto Reference:="test"
    End Sub
    The code I was trying to use for my application is this example:
    http://www.rondebruin.nl/txtcsv.htm

    Everytime I add in my macro I either mess up the code or the macro runs fine but will only add one file. Any suggestion on what can be done to fix it are much appreciated.
    This is my first post here, so please let me know if I should do things differently...Thanks again for your time
    Last edited by arlu1201; 02-11-2013 at 03:29 PM. Reason: Use code tags as per forum rules.

Thread Information

Users Browsing this Thread

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

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