+ Reply to Thread
Results 1 to 3 of 3

Macro to open txt file into a new workbook and save it

  1. #1
    Registered User
    Join Date
    03-12-2012
    Location
    LA, USA
    MS-Off Ver
    Excel 2010
    Posts
    14

    Macro to open txt file into a new workbook and save it

    Hello i want to create a macro that opens a txt file into a newworkbook with only one sheet tap and save it with a specific name

    the open and save directory needs to be dinamic so i can input the path and filename into cells for both open and save

    i manage to open the file and arrange it into columns and rows but opens into the same sheet as my imput path and i canīt save it

    could someone help me

    thanks in advance

    hereīs the file and this is the code i have

    Sub ImportTXT()

    Dim wb As Excel.Workbook
    Dim ws As Excel.Worksheet

    Set wb = Excel.ActiveWorkbook
    Set ws = Excel.ActiveSheet

    ''//This opens the File

    Workbooks.OpenText Worksheets("Main").Range("c4"), Origin:=xlMSDOS, StartRow:=1 _
    , DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, Comma:=True _
    , FieldInfo:=Array(Array(1, xlTextFormat), Array(2, xlTextFormat), _
    Array(3, xlTextFormat))
    ''//The field info array needs to be extended to match your number of columns

    Columns.EntireColumn.AutoFit
    ''//Resize the columns

    Sheets(1).Move Before:=wb.Sheets(1)
    ''//Move the data into the Workbook

    End Sub
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    07-09-2012
    Location
    Pittsburgh, PA USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Macro to open txt file into a new workbook and save it

    I'm having problems understanding what you're trying to do.

    When I run it, it opens the text file, creates a new worksheet in the original workbook (Book1.xlsm), and pastes the data from the text file into it.

    What do you want to happen, instead?

    Also, on a more minor note: your Input_Path_File and Input_File_Name fields are redundant (you included the filename in the Input_Path_File field, and the Output_Path_File and Output_File_Name are probably going to also be redundant.

  3. #3
    Registered User
    Join Date
    03-12-2012
    Location
    LA, USA
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Macro to open txt file into a new workbook and save it

    it will be something like this

    import TXT named in the field Input_File_Name on the path described on Input_Path_File into a new workbook then save the new workbook with the info from the TXT with the name on the field Output_File _Name in the Path described on Output_Path_File.

    Thanks

+ 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