我有这个宏,拉每个文件的第一个选项卡,并将其保存到主文件,但是,我有别人的编码帮助,把它放在一起。我现在想抓住最后一个选项卡,更好的是一个特定的选项卡,“数据选项卡”。有人能看看下面的编码,并帮助我添加吗?谢谢大家!
Sub MASTER_MergeExcelFiles()
Dim fnameList, fnameCurFile As Variant
Dim countFiles, countSheets As Integer
Dim wksCurSheet As Worksheet
Dim wbkCurBook, wbkSrcBook As Workbook
fnameList = Application.GetOpenFilename(FileFilter:="Microsoft Excel Workbooks (*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm", Title:="Choose Excel files to merge", MultiSelect:=True)
If (vbBoolean <> VarType(fnameList)) Then
If (UBound(fnameList) > 0) Then
countFiles = 0
countSheets = 0
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set wbkCurBook = ActiveWorkbook
For Each fnameCurFile In fnameList
countFiles = countFiles + 1
Set wbkSrcBook = Workbooks.Open(FileName:=fnameCurFile)
countSheets = countSheets + 1
wbkSrcBook.Sheets(1).Copy after:=wbkCurBook.Sheets(wbkCurBook.Sheets.Count)
Next
wbkSrcBook.Close SaveChanges:=False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "Processed " & countFiles & " files" & vbCrLf & "Merged " & countSheets & " worksheets", Title:="Merge Excel files"
End If
Else
MsgBox "No files selected", Title:="Merge Excel files"
End If
End Sub
我试着阅读了一遍,但没读出来。
2条答案
按热度按时间t8e9dugd1#
如何将工作表转换为普通值。
2izufjch2#
看起来你在这里得到了一些很好的提示。我想看到这一点通过,所以这里是我的版本。它有一些评论,可能会有帮助。
我采纳了蒂姆·威廉的建议。