这样?
Sub CopyRow()
code = InputBox("请输入代码:", "提示", "600519")
row = 1
writeheader = True
path = "F:\vba\文件数据行提取\excels\" ''''''''''注意改这里为你存储Excel文件的路径
cellnum = 0
f = Dir(path & "*.*") '找目录中的文件
Do Until f = ""
filepath = path & f 'Excel文件路径,注意f只是文件名
Workbooks.Open Filename:=filepath, ReadOnly:=True
If writeheader Then '写入表头
cellnum = Sheets(1).Cells(Rows.Count, 1).End(xlUp).row + 1 '列数
For i = 1 To cellnum
ThisWorkbook.Sheets(1).Cells(row, i + 1) = Sheets(1).Cells(row, i)
Next
writeheader = False
row = row + 1
End If
Set c = Sheets(1).Range("A2:A65535").Find(code)
If Not c Is Nothing Then
ThisWorkbook.Sheets(1).Cells(row, 1) = f
For i = 1 To cellnum
ThisWorkbook.Sheets(1).Cells(row, i + 1) = Sheets(1).Cells(c.row, i)
Next
row = row + 1
End If
Workbooks(2).Close SaveChanges:=False '关闭被打开的Excel
f = Dir '继续遍历下一个文件
Loop
End Sub