+ Reply to Thread
Results 1 to 2 of 2

.txt files (delimiter: comma) into .xls or .xlsx file

Hybrid View

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    9

    .txt files (delimiter: comma) into .xls or .xlsx file

    Hi All,

    I have code written to open a single .txt file (attached), format it using comma as delimiter and save it as either .xls or .xlsx file.

    I need to open multiple files like this. Right now I go back to vba editor, copy the below code, paste it multiple times and only change the name of the .txt file.

    Could anyone help me how I can do the above operation using a simpler code?

    Sub import()
    '
    ' import Macro
    
        fpath = "D:\Desktop\FCST\"
        
        Workbooks.OpenText Filename:= _
            fpath & "\FCST A.txt", Origin:=437, StartRow:=1 _
            , DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
            ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=True, _
            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), Array(9, 1), Array(10 _
            , 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), _
            Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), Array( _
            23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array(29, 1), _
            Array(30, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 1)), _
            TrailingMinusNumbers:=True
        ActiveWorkbook.SaveAs Filename:= _
            fpath & "FCST A.xlsx", FileFormat:=xlOpenXMLWorkbook
    Pradeep M B

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: .txt files (delimiter: comma) into .xls or .xlsx file

    Sub openTextTabDelimited()
    Workbooks.OpenText Filename:="D:\Desktop\FCST\FCST A.txt", _
        DataType:=xlDelimited, TextQualifier:=xlTextQualifierDoubleQuote, Tab:=True, comma:=True
    End Sub
    if problems attach a sample text file
    Last edited by patel45; 04-01-2013 at 10:50 AM.
    If solved remember to mark Thread as solved

+ 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