ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to Remove Macro Text (https://www.excelbanter.com/excel-discussion-misc-queries/147508-macro-remove-macro-text.html)

Rob

Macro to Remove Macro Text
 
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

Dave Peterson

Macro to Remove Macro Text
 
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

Rob wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 08:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com