Sub Copy_Paste()
Dim WB As Workbook
Dim objFileDLG As Office.FileDialog
Dim strFilePath, lnLoop, lnLineNo, lcTargetCell
Set objFileDLG = Application.FileDialog(msoFileDialogFilePicker)
lnLoop = 1
lnLineNo = 2
Do While lnLoop < 6
With objFileDLG
.Filters.Add "Excel Files", "*.xls", 1
.FilterIndex = 1
.AllowMultiSelect = False
.Title = "Select The Workbook to copy From "
If .Show() <> 0 Then
strFilePath = .SelectedItems(1)
End If
End With
Set WB = Workbooks.Open(strFilePath)
WB.Activate
WB.Worksheets(1).Range("B2:H6").Copy
Select Case lnLoop
Case 1
lcTargetCell = "B2"
Case 2
lcTargetCell = "B7"
Case 3
lcTargetCell = "B12"
Case 4
lcTargetCell = "B16"
Case 5
lcTargetCell = "B22"
End Select
ThisWorkbook.Worksheets(1).Activate
Range(lcTargetCell).Activate
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
lnLoop = lnLoop + 1
WB.Close
Set WB = Nothing
Loop
End Sub
|