Results 1 to 2 of 2

How can I write a macro to import multiple text file iinto the same excel worksheet

Threaded View

pvimalmec How can I write a macro to... 10-07-2013, 03:07 PM
alansidman Re: How can I write a macro... 10-07-2013, 04:11 PM
  1. #1
    Registered User
    Join Date
    09-29-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    1

    How can I write a macro to import multiple text file iinto the same excel worksheet

    hello,

    I'm new to VBA macro!!please help me!!

    how can i import a multiple text file(more than 4 files) from a local dir(like D:/Test) into same excel worksheet?

    Also i need to save the imported worksheet in new name in the same dir(D:/Test) (not to save in the macro containing worksheet).


    write now i have used the below code but i m getting all text files in single sheet. i want to get each text in different sheets.

    Sub Read_Text_Files()
    Dim sPath As String, sLine As String
    Dim oPath As Object, oFile As Object, oFSO As Object
    Dim r As Long
    '
    'Files location
    sPath = "D:\Test\"
    '
    r = 1
    Set oFSO = CreateObject( _
    "Scripting.FileSystemObject")
    Set oPath = oFSO.GetFolder(sPath)
    Application.ScreenUpdating = False
    For Each oFile In oPath.Files
    If LCase(Right(oFile.Name, 4)) = ".txt" Then
    '
    Open oFile For Input As #1 ' Open file for input.
    Do While Not EOF(1) ' Loop until end of file.
    Input #1, sLine ' Read data
    If Left(sLine, 1) = "=" Then sLine = "'" & sLine 
    sLine = Replace(sLine, Chr(2), "") 
    sLine = Replace(sLine, Chr(3), "")
    sLine = Replace(sLine, Chr(10), "")
    Range("A" & r).Formula = sLine 
    r = r + 1
    Loop
    Close #1 ' Close file.
    '
    End If
    Next oFile
    '
     'Text to Columns
     Range("A1", Range("A" & Cells.Rows.Count).End(xlUp)).Select
     Selection.TextToColumns DataType:=xlDelimited, _
     TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
     Semicolon:=False, Comma:=False, Space:=True, Other:=False
    Application.ScreenUpdating = True
    End Sub

    thanks in advance,!!
    Last edited by alansidman; 10-07-2013 at 04:11 PM. Reason: code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Import Multiple text files in different worksheet into Excel 2010
    By rageshprasad in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2014, 07:16 AM
  2. Import multiple text file into excel in tabular format
    By kr.sunny007 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2013, 09:32 AM
  3. Replies: 8
    Last Post: 11-12-2012, 02:39 PM
  4. Macro to Parse Text - Import text to Excel from Multiple Text Files & Folders
    By Novice_To_Excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2012, 01:05 AM
  5. [SOLVED] how to import more than 1 text file into the same Excel worksheet.
    By SinnetBS in forum Excel General
    Replies: 1
    Last Post: 06-13-2006, 10:20 PM

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