Hi, I have to import text files (example attached) manually into a spreadsheet and was looking for a simpler, less time consuming method of doing this. I came across some suggestions on this forum that gave me hope that there is a better way. However I don't know much about VBA and have so far being substituting my current macro into some of the suggested solutions posted here. I just cant seem to get it to fully do what I require which is:
1)Take .txt files from a selected folder,
2)Format using macro used for manually adding .txt files
3)Add .txt files into existing spreadsheet into next free column.
The .txt. files are sorted by date in the folder (oldest-newest) and this is the order which I enter them into the spreadsheet. The sheet gets updated weekly with about 20-30 files .txt each time.
The macro I use when manually adding at the moment is:
Sub test()
'
' test Macro
'
'
With ActiveSheet.QueryTables.Add(Connection:="TEXT;F:\129629_$01_121056.txt" _
, Destination:=Range("$A$1"))
.Name = "129629_$01_121056"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ":"
.TextFileColumnDataTypes = Array(1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
ActiveWindow.SmallScroll Down:=-12
Application.Goto Reference:="test"
End Sub
The code I was trying to use for my application is this example:
http://www.rondebruin.nl/txtcsv.htm
Everytime I add in my macro I either mess up the code or the macro runs fine but will only add one file. Any suggestion on what can be done to fix it are much appreciated.
This is my first post here, so please let me know if I should do things differently...Thanks again for your time
Bookmarks