Sub SelectFiles()
Dim FileName$
Dim Path$
' Initialize a string variable for the first file
' in a specified directory. This sets the Dir( )
' function to that directory.
Path$ = InputBox("Enter the path: ", _
"Path", "C:\Temp\test")
Select Case Right$(Path$, 1)
Case "\": FileName$ = Dir(Path$)
Case Else: FileName$ = Dir(Path$ & "\")
End Select
' Loop through the specified directory until the
' Dir( ) function returns an empty string, indicating
' there are not any more contents to be evaluated.
Do While Len(FileName$) > 0
PasteWorksheet Path$ & "\" & FileName$
' Re-initialize the string variable to the next
' file in the directory
FileName$ = Dir()
Loop
End Sub
Sub PasteWorksheet(FileNme$)
Dim wb As Workbook
Application.ScreenUpdating = False
' open the source workbook
Set wb = Workbooks.Open(FileNme$, True, False)
ThisWorkbook.Sheets("MySheet").Copy Before:= _
Workbooks(wb.Name).Sheets(1)
' close the source workbook, saving any changes
wb.Close True
Set wb = Nothing 'free memory
Application.ScreenUpdating = True
End Sub