2,462
社区成员
发帖
与我相关
我的任务
分享
Sub s123()
Dim f$
Dim i As Integer
Dim sh1
Set sh1 = Worksheets(1)
f = Dir(ThisWorkbook.Path & "\*.xls")
Do While f <> ""
If f <> "Book1.xls" And f <> ThisWorkbook.Name Then
Workbooks.Open f
sh1.Cells(i, 1) = Workbooks(f).Sheets(1).Cells(5, 2)
'......................
End If
Workbooks(f).Close False
Loop
End Sub
这样不行在sh1.Cells(i, 1) = Workbooks(f).Sheets(1).Cells(5, 2) Dim i As Integer
Dim sh1, myPath, myfile, wk
Set sh1 = Worksheets(1)
Application.DisplayAlerts = False
myPath = ThisWorkbook.Path & "\"
myfile = Dir(myPath & "\*.xls")
Do While myfile <> "" And myfile <> "Bokk1.xls"
If myfile <> ThisWorkbook.Name Then
Set wk = Workbooks.Open(myPath & "\" & myfile)
i = i + 1
sh1.Cells(i, 1) = wk.Sheets(1).Cells(5, 1)
wk.Close True
End If
myfile = Dir
Loop
Application.DisplayAlerts = True
Ok了