You changed the FolderPicker dialog to a FilePicker dialog. I assume then you just want to copy from the one selected file rather than all the Excel files in a folder. If yes, then you wouldn't use the selected file name as a folder path.
With Application.FileDialog(msoFileDialogFilePicker)
.Show
On Error GoTo errline
sFolder = .SelectedItems(1)
End With
Set wsTo = ThisWorkbook.Sheets("US")
wsTo.Activate
Set rPaste = Application.InputBox("Enter starting cell to paste", Type:=8)
If rPaste Is Nothing Or rPaste.Count > 1 Then Exit Sub
With Application
.ScreenUpdating = False: .DisplayAlerts = False: .EnableEvents = False
End With
On Error Resume Next
With Application.FileSearch
.NewSearch
.LookIn = sFolder
This opens just the one selected file.
Sub search()
Dim nCount As Long, wbResults As Workbook, rPaste As Range, wsTo As Worksheet, wsFrom As Worksheet, sFile As String
With Application.FileDialog(msoFileDialogFilePicker)
.Show
If .SelectedItems.Count = 0 Then Exit Sub
sFile = .SelectedItems(1)
End With
Set wsTo = ThisWorkbook.Sheets("US")
wsTo.Activate
On Error Resume Next
Set rPaste = Application.InputBox("Enter starting cell to paste", Type:=8)(1)
On Error GoTo 0
If rPaste Is Nothing Then Exit Sub
With Application
.ScreenUpdating = False: .DisplayAlerts = False: .EnableEvents = False
End With
Set wbResults = Workbooks.Open(Filename:=sFile, UpdateLinks:=0)
For Each wsFrom In wbResults.Worksheets
With wsTo.Range(rPaste.Address)
.Value = wsFrom.Range("B5").Value
.Offset(, 1).Value = wsFrom.Range("B6").Value
.Offset(, 2).Value = wsFrom.Name
.Offset(1, 3).Resize(11).Value = wsFrom.Range("B10:B20").Value
End With
Set rPaste = rPaste.Offset(13)
Next wsFrom
wbResults.Close SaveChanges:=True
With Application
.ScreenUpdating = False: .DisplayAlerts = True: .EnableEvents = True
End With
End Sub
Bookmarks