将数据粘贴到新工作表时发生Excel VBA错误

我正在粘贴只读取可见行的代码片段,并将其粘贴到新的工作表以进行更多处理。 但是,当它尝试粘贴时,会出现“Excel无法用资源完成操作,请closures一些程序或稍后再试”的错误。 这个代码的任何替代? 顺便说一句,这是超越2007年。

Function createSummary() ActiveSheet.Outline.ShowLevels RowLevels:=2 Cells.Select Selection.SpecialCells(xlCellTypeVisible).Select Application.CutCopyMode = False Selection.Copy Worksheets.Add().Name = "Summary" ActiveSheet.Paste Cells.Font.Bold = False Columns("A").Insert 

没有看到你的工作簿,看起来好像你有某种内存问题。

您不需要select单元格来处理它们。 尝试这样的事情:

 With ActiveSheet .Outline.ShowLevels RowLevels:=2 .UsedRange.SpecialCells(xlCellTypeVisible).Copy Worksheets.Add().[A1] End With With ActiveSheet .Name = "Summary" .UsedRange.Cells.Font.Bold = False .Columns("A").Insert End With