Short macro to Import a text file

zaska

Well-known Member
Joined
Oct 24, 2010
Messages
1,046
Hi all..

Is it possible to shorten this code further...to import a text file..
Code:
With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;E:\Macros\Input\MTO_" & Format(Workbooks("NSE Converter.xls").Sheets("Sheet1").Range("G2").Value, "ddmmyyyy") & ".DAT", Destination:=Range("A1"))
        .Name = "MTO_04012010"
        .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 = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,456
Office Version
  1. 365
Platform
  1. Windows
Why do you feel the need to shorten it?
It is really just one command, with all the settings associated with it. Those shouldn't be slowing it down.
 

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,785
What Joe said.

Although you can hide it away in a separate procedure if you don't want to look at it, and just Call it when it's needed.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,032
Messages
5,526,358
Members
409,697
Latest member
christopherlewis1620

This Week's Hot Topics

Top