excel 宏设计

来源:百度知道 编辑:UC知道 时间:2024/07/07 08:54:09
我有几十个.xls文件,每个文件里都有一个“汇总”工作表,我现在想把这些文件的“汇总”工作表中的第2到第13行,全部粘贴到同一个工作表中,他们的格式都是相同的,请问各位高手如何解决?

录制一个宏,略作修改即可。
或用如下VBA程序:
Private Sub CommandButton1_Click()
Dim TempLen As Byte
Dim TempCount As Integer
Dim strTempPath As String, ViceName As String
Dim fFile As FileSearch
Dim TempMsgBox As VbMsgBoxResult
Set fFile = Application.FileSearch
With fFile
.LookIn = "E:\多个工作簿"
.Filename = "*.xls"
If .Execute > 0 Then
TempMsgBox = MsgBox("共有" & .FoundFiles.Count & "个文件将被汇总", vbOKCancel, "记数")
If (TempMsgBox = vbCancel) Then
End
End If
TempCount = 1
Do
strTempPath = .FoundFiles(TempCount)
Debug.Print strTempPath
TempLen = Len(strTempPath)
ViceName = Mid(strTempPath, Len(fFile.LookIn) + 2, TempLen - Len(fFile.LookIn) - 1)