Results 1 to 8 of 8

Importing a Text File Using a Macro

Threaded View

james_ross Importing a Text File Using a... 01-07-2013, 11:32 AM
Norie Re: Importing a Text File... 01-07-2013, 11:42 AM
patel45 Re: Importing a Text File... 01-07-2013, 11:47 AM
james_ross Re: Importing a Text File... 01-07-2013, 02:54 PM
Norie Re: Importing a Text File... 01-07-2013, 03:57 PM
james_ross Re: Importing a Text File... 01-08-2013, 07:32 AM
PingPing Re: Importing a Text File... 01-07-2013, 06:33 PM
james_ross Re: Importing a Text File... 01-08-2013, 07:36 AM
  1. #1
    Registered User
    Join Date
    01-07-2013
    Location
    Warwickshire, England
    MS-Off Ver
    Excel 2010
    Posts
    7

    Importing a Text File Using a Macro

    Hi,

    I am new to using excel macros and I am wondering how to go about this.

    I need import 4 text files from the same directory. However I need to be able to import the file path into a cell (for example A1), and the file name to be in the macro. I think I have almost done this but I keep getting a run time 1004 error.

    Below is what I have so far to import just 1 text file.

    Sub txt_import()
    '
    ' txt_import Macro
    '
    ' Keyboard Shortcut: Ctrl+t
    
    Dim FilePath As String
    FilePath = Range("A1").Value
    
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;FilePath & Textfile1.txt", Destination:=Range("$A$17"))
            .name = "avg_fft_di_8"
            .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 = True
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = True
            .TextFileColumnDataTypes = Array(1, 1)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
    End With
    End Sub
    If someone could help me with this it would be most appreciated.

    Thanks.

    Moderator's note: Welcome to the forum James. When posting codes they should be enclosed with code tags. Select the code then click the "#" symbol to wrap it with code tags. I'll do it for you now. Thank you!
    Last edited by vlady; 01-07-2013 at 07:37 PM.

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