Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Rob Rob is offline
external usenet poster
 
Posts: 718
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
remove macro Ron New Users to Excel 2 June 1st 06 02:57 PM
Macro to remove text Terry Pinnell Excel Discussion (Misc queries) 5 October 21st 05 11:34 PM
Function to remove a space from text in cell WITHOUT macro?? [email protected] Excel Worksheet Functions 5 May 28th 05 02:28 AM
Macro or Formula to remove Text from Cells smck Excel Worksheet Functions 6 May 11th 05 03:22 AM
How do I change macro text with another macro? Eric Excel Discussion (Misc queries) 4 April 27th 05 11:20 PM


All times are GMT +1. The time now is 09:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"