Deleting worksheet seems to corrupt file on save.

ShakDiesel

New Member
Joined
Aug 8, 2013
Messages
2
I have a vba macro established that processes evaluation data stored across multiple worksheets (one per evaluation) in an external workbook. The macro reads information from the evaluation sheet, makes a copy of the appropriate template worksheet in the active/internal workbook, renames the copied template sheet with the evaluation name, and continues to process the data. All works well the first time through.

The problem arises when new evaluations are added from a different external workbook. If all the evaluations are new, everything works well. If one of the evaluations matches a sheet in the active/internal workbook, the macro gives the user the choice of keeping the old information, or replacing it with the new evaluation data. If they keep the old information, the macro skips to the next eval and all is fine. If they choose to replace, the macro deletes the old worksheet in the active/internal workbook, and processes the evaluation in the external workbook with the same code as every other new evaluation.

As mentioned, everything works fine except this "replace" routine which leads to a "corrupted file" message when the workbook is saved (regardless of the save method). The only difference in the process is the worksheet.delete command. I'm not sure why this would be. The only thing I can point toward is that the "replace" method deletes one worksheet, but then creates a new worksheet and gives it the same name as the deleted worksheet. However, I don't know why that would matter. Any ideas?
 
Update: It is not the name being the same that is the problem. Tried to give the replacement a new name, and got the same problem.

It is not deletion of a sheet in general that is the problem. If I manually delete the worksheet I plan to replace before running the macro, the macro processes the replacement evaluation as if it was a new evaluation and everything runs properly. If the old sheet is deleted programmatically, still get the corrupted file.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top