I think you can leave the names of the files alone, if they always start with ToadExport that can be removed explicitly, or at least the date immediately after can be found easily.
1) Remove all code trom ThisWorkbook module. That module is for workbook level event code, not on-demand macros like this.
2) Add an empty standard code module (Insert > Module), then paste in this new version of the macro:
Option Explicit
Sub CollectData()
'Author: Jerry Beaucaire, ExcelForum.com
'Date: 11/23/2010 (9/20/2011)
'Summary: Open all the files in a specific folder and add key data to database
' moves imported files to "imported" folder to preclude repeats
Dim fPath As String, fDone As String
Dim fName As String, fDate As String
Dim wsData As Worksheet, wbImp As Workbook
Dim dRow As Long, ErrMsg As String
'Setup
Application.ScreenUpdating = False
Set wsData = ThisWorkbook.Sheets("Data")
fPath = "C:\2011\Test\"
fDone = "C:\2011\Test\Imported\"
fName = Dir(fPath & "*.xlsx")
On Error Resume Next
'Collect data
Do While Len(fName) <> 0
fDate = Format(Left(Replace(fName, "ToadExport", ""), 10), "M/D/YYYY")
If IsDate(fDate) Then
dRow = wsData.Range("A:A").Find(fDate, LookIn:=xlValues, LookAt:=xlWhole).Row
If dRow <> 0 Then
Set wbImp = Workbooks.Open(fPath & fName)
wsData.Range("B" & dRow).Resize(, 8).Value = _
WorksheetFunction.Transpose(wbImp.Sheets(1).Range("C2:C9").Value)
wbImp.Close False
Name (fPath & fName) As (fDone & fName)
Else
ErrMsg = ErrMsg & vbLf & " " & fName
End If
Else
ErrMsg = ErrMsg & vbLf & " " & fName
End If
fName = Dir
dRow = 0
Loop
If ErrMsg <> "" Then MsgBox "The following files were not processed:" & vbLf & ErrMsg
Application.ScreenUpdating = True
End Sub
'Note the fPath and the fDone strings...
'fPath is the directory where the files are found, remember the final \ in that string
'fDone is where the files are moved to after they are imported so you know they are done. Create that directory if needed.
'Errors are buffered and presented as a list of files that were not processed at the end. Try putting a garbage file in that directory that isn't named for a date and you'll see.
Notice my fPath and fDone strings end with a \ while the code I found in the wb you uploaded did not.
Bookmarks