Excel 2007 sheet copy: Application-defined or object-defined error

When you use the code sheet.copy normally a new workbook is created with a copy of that particular sheet.
However in Excel 2007 (SP1) if the original workbook contains a macro when you run the code the first time you (might) get the following error:
excel-2007-application-or-object-defined-error.png

I could only reproduce this error when the original workbook where the sheet was copied from contained a macro and only when the code was run the first time via a button from the ribbon. If I ran the code again or when I ran the code from within the Visual Basic editor it worked without the error.
The error is an untrappable one, meaning that "on error goto" doesn't work for this error so you cannot create a workaround for this in your code or present the user a more descriptive and friendly message.

Comments are closed.

Pinterest