Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88081

Method 'Copy' of object '_Worksheet' failed

$
0
0

For the first time I now faced the error

Method 'Copy' of object '_Worksheet' failed

I heard that this is a quite common error but I was not able to find a solution. When I searched trough SO, I found many posts about the

'Range' of object failed-Error.

Is this error caused by memory limitations of the workstation or is it a software related error?

Anyone got an idea to work around that problem?

In case it is of interest that is my VBA code:

Private Sub CommandButton1_Click()
MsgBox "Message"

  Dim wb As Workbook
  Set wb = Workbooks.Add(xlWBATWorksheet)
  wb.Sheets(1).Name = "deletethissheet"

  Dim ws As Worksheet
  For Each ws In ThisWorkbook.Worksheets
    ws.Copy After:=wb.Sheets(wb.Sheets.Count)
  Next

  For Each ws In wb.Worksheets
    ws.UsedRange.Formula = ws.UsedRange.Value

    Dim sh As Shape
    For Each sh In ws.Shapes
      sh.Delete
    Next

  Next

  For Each Link In wb.LinkSources(xlLinkTypeExcelLinks)
  wb.BreakLink Name:=Link, Type:=xlLinkTypeExcelLinks
  Next

  wb.Sheets("deletethissheet").Delete
  wb.SaveAs Replace(ThisWorkbook.FullName, ".xlsm", "_"& Format(Date, "yyyymmdd") & ".xlsx"), xlOpenXMLWorkbook
  wb.Close SaveChanges:=False

End Sub

ws.Copy After:=wb.Sheets(wb.Sheets.Count) Is the cause of the error.


Viewing all articles
Browse latest Browse all 88081

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>