
VBA
VBA代码如下:Sub 文件合并()If Workbooks.Count 1 Then MsgBox 关闭所有工作簿,然后再试!: Exit SubDim fn As String, mPath As String, wb As Workbook, sh As WorksheetDim tt = TimerWith Application.FileDialog(msoFileDialogFolderPicker) .AllowMultiSelect = False .Show If .SelectedItems.Count = 0 Then MsgBox 没有选择任何文件夹! Exit Sub Else mPath = .SelectedItems(1) End IfEnd Withfn = Dir(mPath & *.xls*)Application.ScreenUpdating = FalseDo While fn If fn ThisWorkbook.Name Then k = k + 1 Set wb = Workbooks.Open(mPath & & fn, , True) With wb.Worksheets(1) mary = .Range(A1).CurrentRegion