|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 复制粘贴()
- Application.ScreenUpdating = False
- Dim fp$, obmapp As Object
- Dim Xls, i As Long, lj As String
- Set obmapp = CreateObject("Shell.Application").BrowseForFolder(0, "请选择文件目录:", 0, 0)
- If Not obmapp Is Nothing Then
- fp = obmapp.Self.path & ""
- Else
- Exit Sub
- End If
- Xls = Dir(fp & "*.xls") '指定要遍历excel文件的路径及文件类型
- Do While Xls <> ""
- If Xls <> ThisWorkbook.path Then
- Set Xls = Workbooks.Open(fp & Xls) '打开excel文件,“\”要留着
- a = Application.WorksheetFunction.Match(Workbooks(1).Sheets(1).Cells(1, 1), Workbooks(2).Sheets(1).[a1:a5])
-
- ls = Workbooks(1).Sheets(1).Cells(3, 300).End(xlToLeft).Column + 1
-
- b = Application.WorksheetFunction.Match(Workbooks(2).Sheets(1).Cells(2, 2), Workbooks(1).Sheets(1).[a2:i2])
-
- c = Application.WorksheetFunction.Match(Mid(Workbooks(2).Name, 1, 2), Workbooks(1).Sheets(1).[a1:a5])
-
- Workbooks(2).Sheets(1).Range(Workbooks(2).Sheets(1).Cells(a, 2), Workbooks(2).Sheets(1).Cells(a, Workbooks(2).Sheets(1).Cells(a, 300).End(xlToLeft).Column)).Copy Workbooks(1).Sheets(1).Cells(c, b)
-
-
- End If
- Loop
- Set Xls = Nothing '释放变量内存
-
- End Sub
复制代码
这个我写的,不过比不上上面的 |
|