+ Reply to Thread
Results 1 to 3 of 3

Import txt macro with range

Hybrid View

  1. #1
    Registered User
    Join Date
    10-11-2009
    Location
    Athens
    MS-Off Ver
    Excel 2003
    Posts
    10

    Import txt macro with range

    Hello, I have tried lots of things but, no luck.
    I want a macro to insert, lots of txt files into an xls.
    Some files on the same sheet, some not.
    Each value on diferent cell
    I can't figure out how to put each txt where I want it.
    etc 1.txt at cell C5, 2.txt at k5 and 3.txt at O5, and other txt at other sheets.
    Thanks a lot.

    Sub Import_Text()
        Dim DestCell As Range
         'Variable to capture full path of selected text file
        Dim strFullPath, tmp As String
         'Get a text file  name
        strFullPath = Application.GetOpenFilename("Text Files (*.txt),*.txt", , "Please select a text file to import...", "C:\TYPO_MANIN\Macro\1WeeksMeasurements")
         'Exit the macro if the user has pressed Cancel on the open file dialog
        If strFullPath = "False" Then Exit Sub
        
    
    'Μπορώ να δηλώσω text = xlMacintosh από το Origin
    
       Workbooks.OpenText Filename:=strFullPath, Origin _
           :=437, StartRow:=6, DataType:=xlDelimited, TextQualifier:= _
           xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
           Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
           Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1)), _
           TrailingMinusNumbers:=True
          
          
    End Sub

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Import txt macro with range

    Try something like this

    
    Dim StartCell As Range
    
    'repeat as necessary
    Open "MyTxtFile.txt" For Input As #1
    Set StartCell = Cells(4, 5)
    Do While Not EOF(1)
        Line Input #1, FileLine
        Counter = Counter + 1
        LineArray = Split(FileLine, Chr$(9)) 'Assuming tab separated
        For X = 0 To UBound(LineArray)
            StartCell.Offset(Counter - 1, X) = LineArray(X)
        Next X
    Loop
    Close #1
    Martin

  3. #3
    Registered User
    Join Date
    10-11-2009
    Location
    Athens
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Import txt macro with range

    thanks a lot, I added a few things and worked great

+ Reply to Thread

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