|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 合并()
- Dim Items As FileDialogSelectedItems, strPath$
- Dim sh As Worksheet
- Set sh = ThisWorkbook.Sheets(1)
- Set fso = CreateObject("scripting.filesystemobject")
- strPath = ThisWorkbook.Path & ""
- With Application.FileDialog(1)
- With .Filters
- .Clear
- .Add "Excel Files", "*.xls*"
- End With
- .AllowMultiSelect = True
- .InitialFileName = strPath
- If .Show Then Set Items = .SelectedItems Else Exit Sub
- End With
- Application.ScreenUpdating = False
- sh.UsedRange.Clear
- For Each vItem In Items
- t = VBA.InStrRev(vItem, "")
- t2 = VBA.InStrRev(vItem, ".")
- tt = Mid(vItem, t + 1, t2 - t - 1)
- With GetObject(vItem)
- If sh.[A1] = "" Then
- .Sheets(1).[a1:e100].Copy sh.[A1]
- c = sh.Cells(1, 100).End(xlToLeft).Column + 1
- sh.Cells(1, c) = tt
- Else
- icol = sh.Range("aa2").End(xlToLeft).Column + 2
- .Sheets(1).[a1:e100].Copy sh.Cells(1, icol)
- c2 = sh.Cells(1, 100).End(xlToLeft).Column + 1
- sh.Cells(1, c2) = tt
- End If
- .Close False
- End With
- Next
- Set Items = Nothing
- Application.ScreenUpdating = True
- Beep
- End Sub
复制代码 |
|