LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Self destructing code

Here's the code I need to run:

*****
Sub renamer()

Dim mySht As Worksheet
'Dim VBComp As VBComponent

Application.DisplayAlerts = False
TabName = Range("A1").Value
ActiveSheet.Name = TabName
ActiveSheet.SaveAs (TabName)

For Each mySht In ActiveWorkbook.Worksheets
If mySht.Name < TabName Then mySht.Delete
Next mySht
Application.DisplayAlerts = True

Set VBComp = ThisWorkbook.VBProject.VBComponents("Module1")
ThisWorkbook.VBProject.VBComponents.Remove VBComp

End Sub
*****

The idea of this code is to rename, clean up, and save a workbook then
delete the VB module that called it. The end result/output file can then be
passed on without the end user panicking over whether or not to access macros
etc etc. Problem is, the code does everything it's supposed to up to the
point of renaming and saving, but then it deletes itself. So, it saves the
copy *with* code where I want a copy saved *without* code. Of course, if I
re-arrange the lines to make the macro delete the code before saving, it
won't work...

Effectively the snake eats its own tail ;-) Does anyone have a smart way to
make the code hold off module deletion, or even better to delete the code
from the new file and then save - or am I quite simply (as usual) asking the
impossible?
 
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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Code to conditional format all black after date specified in code? wx4usa Excel Discussion (Misc queries) 3 December 26th 08 07:06 PM
Self Destructing Spreadsheet Chris Excel Discussion (Misc queries) 1 August 8th 08 03:14 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
stubborn Excel crash when editing code with code, one solution Brian Murphy Excel Programming 0 February 20th 05 05:56 AM


All times are GMT +1. The time now is 01:28 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"