Import fixed width text file macro

Joined
Sep 4, 2008
Messages
2
Reaction score
0
Each week I have to import a new text file into Excel. The file names change each time, but the fixed width set up is the same. I tried creating a macro so that I would not have to repeat the setting of field widths every time, but when I modify the code and add GetOpenFilename to allow for the search and opening of a different file, it won't work. I have followed instructions on various sites, but nothing works. Here is the code generated by the macro. I have to change the beginning so it doesn't point to a specific file. Can anyone give me that piece of code?

Sub Macro8()

'

' Macro8 Macro

'

'

With ActiveSheet.QueryTables.Add(Connection:= _

"TEXT;X:\VENDOR\BANKING\SFFI\Text Files\Unprocessed SFFIs\sffi 632 .txt", _

Destination:=Range("$A$2"))

.Name = "sffi 632 "

.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(2, 2, 2, 2, 2, 1, 5, 5, 1, 1, 2, 2, 2, 2, 2)

.TextFileFixedColumnWidths = Array(5, 13, 6, 8, 3, 3, 6, 6, 5, 7, 2, 1, 4, 10)

.TextFileTrailingMinusNumbers = True

.Refresh BackgroundQuery:=False

End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top