Hello,
I am currently using VBA code to import multiple .txt and .tab files into excel which bypasses the Import Wizard. Even if I utilize the Import Wizard, I am restricted to one file at a time and have to change each data format field from "general" to "text" which can be very tedious to say the least. I am having another issue with this code importing each header row in the files while I only want one, but will address this in another thread.....As for what I am looking for here.....Simply put..... I would like the following code, or a similar code that does the same thing, to import all fields as "text" not "general".
Please find attached example of workbook and source file.... Any assistance in this matter will be greatly appreciated..... Regards.... Delta![]()
Sub Import_Tab() Dim myFolder, TabFile, fso As Object, fPath As String ' Turn off some Excel functions that are not needed With Application .ScreenUpdating = False .EnableEvents = False .Calculation = xlCalculationManual End With ' Import files Set fso = CreateObject("Scripting.FileSystemObject") With Application.FileDialog(msoFileDialogFolderPicker) .AllowMultiSelect = False .Show If .SelectedItems.Count > 0 Then fPath = .SelectedItems(1) & "\" Else Exit Sub End With Set myFolder = fso.GetFolder(fPath).Files ' Open each file sequentially For Each TabFile In myFolder If LCase(TabFile) Like "*.tab" Then ' Import data from Text file With Workbooks.Open(Filename:=TabFile, Delimiter:=1) With ThisWorkbook.ActiveSheet ActiveSheet.UsedRange.Copy _ Destination:=.Cells(.Rows.Count, "A").End(xlUp)(2) End With .Close SaveChanges:=False End With End If Next TabFile ' clean up TabFile = vbNullString ' Turn Excel functions back on With Application .Calculation = xlCalculationAutomatic .DisplayStatusBar = True .EnableEvents = True End With End Sub
Bookmarks