Importing text file into excel
Need to do the same thing that does the Data-Import External Data-Edit Text Import, for to import a file that every day has a different extension:
UT4.1
.
.
.
UT4.n
n should be the value taken from a user form.
I make a macro that for e.g. imports the file UT4.133 but when I go to VBA and try to change the extension of the file to "X:\labi\K96_2005\K96\IZVESTAJ\" & [Forms]![UserForm1]![TxtBox1]
it gives a 1004 error.
Sub LABOR()
'Dim GetFileName
' LABOR Macro
' Macro recorded 17.1.2007 by anamarija
'
'
With Selection.QueryTable
.Connection = "TEXT;" & "X:\labi\K96_2005\K96\IZVESTAJ\" & [Forms]![UserForm1]![TxtBox1]
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1)
.TextFileFixedColumnWidths = Array(1)
.TextFileDecimalSeparator = "."
.TextFileThousandsSeparator = ","
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
'.Filename = GetFileName()
End With
Sheets("pg 1").Select
ActiveWindow.SmallScroll Down:=42
End Sub
Is there any other simplest way to do this kind of operation?
|