I put it in but now it is not importing anyting.... I am going nuts.
What did I miss.
Sub ImportTXTsWithReference()
'Author: Jerry Beaucaire
'Date: 10/16/2010
'Summary: Import all CSV files from a folder into a single sheet
' adding a field in column A listing the CSV filenames
Dim wbTXT As Workbook
Dim wsMstr As Worksheet
Set wsMstr = ActiveSheet
If MsgBox("Inport and clear the existing Scanner Data?", vbYesNo, "Clear?") _
= vbYes Then wsMstr.Range("DataTable").Clear
Dim fPath As String: fPath = BrowseForFolderShell 'path to TXT files, include the final \
Dim fTXT As String
Application.ScreenUpdating = True 'speed up macro
fTXT = Dir(fPath & "*.csv") 'start the TXT file listing
Do While Len(fTXT) > 0
'temporarily rename the file
Name fPath & fTXT As fPath & Replace(fTXT, ".txt", ".csv")
'open a CSV file
Set wbTXT = Workbooks.Open(fPath & fTXT)
'insert col A and add CSV name
Columns(1).Insert xlShiftToRight
Columns(1).SpecialCells(xlBlanks).Value = ActiveSheet.Name
'copy date into master sheet and close source file
ActiveSheet.UsedRange.Copy wsMstr.Range("A" & Rows.Count).End(xlUp).Offset(1)
wbTXT.Close False
'put the filename back
Name fPath & fTXT As fPath & Replace(fTXT, ".csv", ".txt")
'ready next CSV
fTXT = Dir
Loop
Application.ScreenUpdating = True
End Sub
Function BrowseForFolderShell() As String
Dim objShell As Object, objFolder As Object
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Please select a folder", 0) 'SpecFolders.CSIDL_FAVORITES
BrowseForFolderShell = CStr(objFolder.items.Item.Path & Application.PathSeparator)
End Function
Bookmarks