jbragg6625
New Member
- Joined
- Dec 3, 2015
- Messages
- 5
Hello,
I am very inexperienced at create macros but need to make one that will import all the text files from a specific folder. I tried using the macro recorder to do this but I'm not sure how to change the code so that it repeats the import process for each text file.
Also I need the last four rows of data from each text file to be deleted when they are imported.
This is the code that I currently have. It allows works on a specific file but not all files in the folder.
Can anyone help me with this?
I am very inexperienced at create macros but need to make one that will import all the text files from a specific folder. I tried using the macro recorder to do this but I'm not sure how to change the code so that it repeats the import process for each text file.
Also I need the last four rows of data from each text file to be deleted when they are imported.
Code:
Sub Transform()
'
' Transform Macro
' Transform JPMC File
'
' Keyboard Shortcut: Ctrl+t
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:Text Files\161.txt", Destination:=Range( _
"$A$1"))
.Name = "161"
.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 = 9
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 9, 2, 9, 2, 1, 2, 2, 1)
.TextFileFixedColumnWidths = Array(16, 8, 11, 8, 16, 6, 12, 33)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=True
End With
Worksheets("Sheet1").Activate
ActiveCell.CurrentRegion.Select
End Sub
This is the code that I currently have. It allows works on a specific file but not all files in the folder.
Can anyone help me with this?