|
楼主 |
发表于 2017-4-6 11:23
|
显示全部楼层
Sub 打开文件()
Dim path$, xl$, i%, rn As Range
path = Cells(3, 2).Value
xl = Dir(path & "\*.xls")
i = 1
rn = ThisWorkbook.Worksheets(2).Range("A:A")
Application.ScreenUpdating = False
Do While xl <> "" And xl <> rn.Value
Workbooks.Open Filename:=path & "\" & xl
ThisWorkbook.Worksheets(2).Cells(i, 1) = xl
Workbooks(xl).Worksheets(1).Cells(3, 2).Copy Destination:=ThisWorkbook.Worksheets(2).Cells(i, 2)
Workbooks(xl).Worksheets(1).Cells(3, 4).Copy Destination:=ThisWorkbook.Worksheets(2).Cells(i, 3)
ThisWorkbook.Worksheets(2).Cells(i, 4).FormulaR1C1 = "=R[0]C[-1]+R[0]C[-2]"
Workbooks(xl).Close 0
i = i + 1
xl = Dir
Loop
Application.ScreenUpdating = True
End Sub
我还想问下 如果我想要添加更新的功能 就是新增文件名称和已经在A列的文件名称不重复 我这样操作是不对的 我想知道需要如何操作呢 |
|