Macro to Remove Macro Text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm wondering if it is possible to have a macro that would delete all macros
from the "ThisWorkbook" section when the workbook is saved?

The reason I ask is because I have a macro within the "ThisWorkbook" section
that does a few things automatically when the workbook is opened. However,
before the populated workbook is saved some of the worksheets that are
referenced in that opening macro are no longer there so the next time the
spreadsheet is opened I now get errors.

A long winded explaination but I just wanted to know if it was possible to
do it.

Thanks in advance.
Rob
 
Check out Chip Pearson's site:
http://cpearson.com/excel/vbe.htm

He shows how to write code that modifies code.

An alternative would be to check for a worksheet that's already gone. If it's
not there, you know not to continue with the rest of the code.


Option Explicit
Sub Workbook_Open()
dim testWks as worksheet
set testwks = nothing
on error resume next
set testwks = me.worksheets("sheetthatsdeleted")
on error goto 0

if testwks is nothing then
'it's already gone
exit sub
end if

'reset of code here

End Sub
 
Back
Top