Macro to delete sheets and saves remaining file does not properly delete module

P

pherrero

I have a macro that has the user save the file through a command butto
rather than the regular save. This macro checks for data entry errors
deletes sheets that were not selected for data entry, and saves th
remaining file.

However, the sheet module from the deleted sheets does not get delete
(when I say delete, I do not mean that I want the code in the module t
be blanked; I mean that the module should no longer appear in VBE jus
as the sheet does not appear in the Excel interface).

Simplified code:

Private Sub deleteandsave()
Sheet1.Delete
ThisWorkbook.Save
End Sub

If you look at VBE after running this, the sheet module for Sheet1 doe
indeed get deleted. However, the file that was actually saved maintain
the sheet module although the worksheet itself was deleted. This i
effect produces a file with a sheet module that is linked to th
"ether". This unlinked sheet module can have strange behavior on th
rest of the file even if blank.

Any suggestions that makes sure that the module gets deleted before th
save command is run? (I prefer that Save is not a separate action - I
you delete sheets and then Save as two independent actions - tw
buttons - the unlinked sheet module does not occur
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top