This strip of code is designed to open all .raw delimited text files in a folder, delimit them, and save them in another folder in .xlsm format. The script runs in a blank workbook and opens a text file one at a time in another workbook.
It gets as far as opening the first .raw file in the folder and then immediately failing. I am assuming that I am not properly activating the workbook I just opened.
Note that I cut some of the code out that isn't relevant to this question.
If my assumption is correct, how do I properly activate the workbook?![]()
Sub Consolidate() Dim Coll_Docs As New Collection Dim Search_path, Search_Filter, Search_Fullname As String Dim DocName As String Dim i As Long Search_path = "C:\Users\nathaniel\Desktop\Compression Data" Search_Filter = "*.raw" Set Coll_Docs = Nothing DocName = Dir(Search_path & "\" & Search_Filter) Do Until DocName = "" Coll_Docs.Add Item:=DocName DocName = Dir Loop For i = Coll_Docs.Count To 1 Step -1 Search_Fullname = Search_path & "\" & Coll_Docs(i) Application.Workbooks.Open (Search_Fullname) Workbooks(Coll_Docs(i)).Activate ***Fails after workbook is open*** Columns("A:A").Select Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, Comma:=True ActiveSheet.Name = Material & Temperature ActiveWorkbook.SaveAs "C:\Data\" & Material & " " & Temperature & ".xlsm", FileFormat:=52 ActiveWorkbook.Close False Next End Sub
Thanks!
Bookmarks