+ Reply to Thread
Results 1 to 3 of 3

better way to import text file

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2021
    Posts
    351

    better way to import text file

    I have the following code, is there a better way to do this.

    Import text file int a sheet

    Sub UnixoIM()
    
        Sheets("UnixO").Select
        Range("A1").Select
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;D:\Users\hbezuidenhout\Documents\UnixO Tapes.txt", Destination:=Range( _
            "$A$1"))
            .Name = "UnixO Tapes"
            .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, 1, 1, 1)
            .TextFileFixedColumnWidths = Array(11, 16, 10, 10, 12, 10, 15, 11, 9)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
           
        End With
    End Sub
    
    Sub UnixnIM()
      Sheets("UnixN").Select
        Range("A1").Select
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;D:\Users\hbezuidenhout\Documents\UnixN Tapes.txt", Destination:=Range( _
            "$A$1"))
            .Name = "UnixN Tapes"
            .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, 1, 1, 1)
            .TextFileFixedColumnWidths = Array(11, 16, 10, 10, 12, 10, 15, 11, 9)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
           End With
    End Sub
    
    Sub WVMim()
     Sheets("VM").Select
        Range("A1").Select
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;D:\Users\hbezuidenhout\Documents\Windows VM Tapes.txt", Destination:=Range( _
            "$A$1"))
            .Name = "Windows Vm Tapes"
            .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, 1, 1, 1)
            .TextFileFixedColumnWidths = Array(11, 16, 10, 10, 12, 10, 15, 11, 9)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
           
        End With
    End Sub
    Sub WGPim()
     Sheets("GP").Select
        Range("A1").Select
        With ActiveSheet.QueryTables.Add(Connection:= _
            "TEXT;D:\Users\hbezuidenhout\Documents\Windows GP Tapes.txt", Destination:=Range( _
            "$A$1"))
            .Name = "Windows GP Tapes"
            .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, 1, 1, 1)
            .TextFileFixedColumnWidths = Array(11, 16, 10, 10, 12, 10, 15, 11, 9)
            .TextFileTrailingMinusNumbers = True
            .Refresh BackgroundQuery:=False
          
        End With
    End Sub

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: better way to import text file

    Hello
    Attach sample of your text file and show the desired output in excel file to find proper help
    Regards
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Johannesburg, South Africa
    MS-Off Ver
    2021
    Posts
    351

    Re: better way to import text file

    Here are the link on two screenshots of my text file and how it should look in excel

    https://drive.google.com/file/d/0B87...ew?usp=sharing
    https://drive.google.com/file/d/0B87...ew?usp=sharing

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Export specific range to text file and import the text file if needed
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-06-2015, 07:38 AM
  2. Replies: 7
    Last Post: 10-30-2012, 07:14 AM
  3. [Ask] Import Text file And Call reference path file with Value Range.
    By dha_indra in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2012, 11:09 PM
  4. [SOLVED] Import text file from VBA code; import all numbers as text
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-19-2012, 05:19 PM
  5. VBA code to import text file to the fixed excel file
    By wangdian in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-30-2010, 10:13 AM
  6. [SOLVED] Would Like to Automate Batch File Creation and Text FIle Import
    By socrtwo in forum Excel General
    Replies: 2
    Last Post: 08-18-2006, 11:00 AM
  7. [SOLVED] How do I import text file, analyze data, export results, open next file
    By Geoffro in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-06-2005, 04:06 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