Sub 正確可執行()
Workbooks(1).Worksheets("test").Activate
For i = 3 To 5
sname = Workbooks(1).Worksheets("test").Cells(i, 1)
Workbooks.Open Filename:=ThisWorkbook.Path & "\" & sname & ".xlsx"
If Application.Sum(Workbooks(2).Worksheets("cr").Range("b2:b5")) > 0 Then
Workbooks(1).Worksheets("test").Cells(i, 5) = Application.Sum(Workbooks(2).Worksheets("cr").Range("b2:b5"))
End If
Workbooks(2).Close
Next
End Sub
Sub 錯誤不可執行()
Workbooks(1).Worksheets("test").Activate
For i = 3 To 5
sname = Workbooks(1).Worksheets("test").Cells(i, 1)
Workbooks.Open Filename:=ThisWorkbook.Path & "\" & sname & ".xlsx"
If Application.Sum(Workbooks(2).Worksheets("cr").Range(Cells(11, 2), Cells(11, 5))) > 0 Then
Workbooks(1).Worksheets("test").Cells(i, 5) = Application.Sum(Workbooks(2).Worksheets("cr").Range(Cells(11, 2), Cells(11, 5)))
End If
Workbooks(2).Close
Next