Results 1 to 8 of 8

Macro for Import Text file and convert it in Excel

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-17-2014
    Location
    INDIA
    MS-Off Ver
    Excel 2010
    Posts
    332

    Macro for Import Text file and convert it in Excel

    Today i am facing a problem...........i want to make many macro and try it on my Text file but nothing is going to right........

    Below code i got from Recording Macro.........Below code including Text File opening + Set Break Line + Sort on COL-A and more more more................

    i am looking for a solution, i want to make it dynamically......means that when i click on Commandbutton1, a open dialog box should be open like CTRL+O, where i choose my TextFile from my Desktop and it convert in Excel.........
    Please see the excel file's Sheet Deletion

    I am attaching 2files i.e. 1. TextFile and 2. Excel File, please see


    Sub Macro4()
    '
    ' Macro4 Macro
    '
    
    '
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;C:\Users\Gyan Verma\Desktop\July-2018 Advance\slgt0718.prn", Destination _
            :=Range("$A$1"))
            .CommandType = 0
            .Name = "slgt0718"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = 437
            .TextFileStartRow = 1
            .TextFileParseType = xlFixedWidth
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = False
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = False
            .TextFileSpaceDelimiter = False
            .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
            .TextFileFixedColumnWidths = Array(8, 10, 8, 20, 25, 7)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
        End With
        Cells.Select
        ActiveWorkbook.Worksheets("Sheet4").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet4").Sort.SortFields.Add Key:=Range("A1:A122") _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Sheet4").Sort
            .SetRange Range("A1:G122")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        ActiveWindow.SmallScroll Down:=48
        Rows("50:50").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Delete Shift:=xlUp
        Selection.End(xlUp).Select
        Selection.End(xlUp).Select
        Rows("1:1").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("A1").Select
        ActiveCell.FormulaR1C1 = "S.No."
        Range("B1").Select
        ActiveCell.FormulaR1C1 = "Sheet_Code"
        Range("C1").Select
        ActiveCell.FormulaR1C1 = "E_Code"
        Range("D1").Select
        ActiveCell.FormulaR1C1 = "E_Name"
        Range("E1").Select
        ActiveCell.FormulaR1C1 = "Designation"
        Range("F1").Select
        ActiveCell.FormulaR1C1 = "AMT"
        Range("G1").Select
        ActiveCell.FormulaR1C1 = "Department"
        Selection.End(xlToLeft).Select
        Range(Selection, Selection.End(xlToRight)).Select
        Selection.Font.Bold = True
        Cells.Select
        Cells.EntireColumn.AutoFit
        Selection.End(xlToLeft).Select
        Selection.End(xlUp).Select
        Sheets("Sheet4").Select
        Sheets("Sheet4").Name = "Deletion"
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need a Macro code to convert Text file into Excel format
    By Vel Iyappan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2017, 08:00 AM
  2. VBA code to Convert Excel to Text file of DML statements(Insert) using Macro
    By kavitha.v in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2014, 08:52 AM
  3. How can I write a macro to import multiple text file iinto the same excel worksheet
    By pvimalmec in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2013, 04:11 PM
  4. Import several text files into an excel file with macro
    By rhkm in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2013, 05:04 AM
  5. Replies: 8
    Last Post: 11-12-2012, 02:39 PM
  6. Import Tab Seperated Text File Into Excel Using Macro
    By SameeraCharabudla in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2012, 11:57 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