|
1552174482 发表于 2014-1-11 20:41
比如我要从所有sheet1的第4行开始合并,因为前三行是公司抬头什么的,我不需要。
需要在您的宏里改哪些值 ... - Sub 工作表()
- Dim sFile$
- Dim sPath
- Dim wbSource As Workbook
- Dim strErrMsg As String
- Dim shtDst As Worksheet
- Dim arr, arrHeader
- Dim lRow As Long
- Dim HasHeader As Boolean
- Do While Len(sFile) > 0
- If Not sFile Like ThisWorkbook.Name Then
- Set wbSource = GetObject(sPath & sFile)
- With wbSource.Worksheets("sheet1")
- With .UsedRange
- arrHeader = .Rows("1:3").Value
- arr = .Rows("4:" & .Rows.Count).Value
- End With
- End With
- wbSource.Close False
- With shtDst
- If Not HasHeader Then
- .Range("a1").Resize(UBound(arrHeader), UBound(arrHeader, 2)).Value = arrHeader
- HasHeader = True
- End If
- lRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
- .Cells(lRow, 1).Resize(UBound(arr), UBound(arr)) = arr
- End With
- Set wbSource = Nothing
- Else
- strErrMsg = strErrMsg & sFile & "读取错误"
- Set wbSource = Nothing
- End If
- sFile = Dir
- Loop
- MsgBox "数据已经汇总在" & ActiveWorkbook.Name & " 的 " & ActiveSheet.Name & vbCr & "按确定后开始保存", vbInformation + vbOKOnly
- ActiveWorkbook.Save
- Application.ScreenUpdating = True
- If Len(strErrMsg) > 0 Then
- MsgBox strErrMsg
- Else
- MsgBox "合并完成"
- End If
- End Sub
复制代码 你自己测下吧,我这没法测。
|
|