|
求大神指教为什么With GetObject(MyPath & MyName)在公司共享文件夹运行错误,在本地又可以运行,多谢啦
Sub 合并分表()
Dim MyPath$, MyName$, sh As Worksheet, sht As Worksheet, m&
If ActiveSheet.Name <> "汇总" Then
MsgBox "请选中【汇总】工作表"
Exit Sub
End If
Sheet1.Range("A2:N6000").Cells.ClearContents '合并前先清空数据
Set sh = ActiveSheet
MyPath = ThisWorkbook.Path & "\"
MyName = ThisWorkbook.Name
Application.ScreenUpdating = False
With GetObject(MyPath & MyName)
On Error Resume Next
For Each sht In .Sheets '循环工作薄中的所有工作表sht
If sht.Name <> "汇总" And sht.Name <> "透视" Then
If IsSheetEmpty = IsEmpty(sht.UsedRange) Then
If Sheets("汇总").FilterMode Then Sheets("汇总").ShowAllData
If sht.FilterMode Then sht.ShowAllData
n = sht.[b65536].End(xlUp).Row '将要合并的工作表中数据行数
m = sh.[b65536].End(xlUp).Row '合并前【汇总表】工作表中数据行数
arr = sht.Range("a2:m" & n)
sh.Cells(m, 1).Offset(1).Resize(n - 1) = sht.Name
sh.Cells(m, 2).Offset(1).Resize(UBound(arr), UBound(arr, 2)) = arr
End If
End If
Next
End With
Application.ScreenUpdating = True
MsgBox "合并完成"
End Sub
|
|