Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
split post code (zip code) out of cell that includes full address | Excel Discussion (Misc queries) | |||
Code to conditional format all black after date specified in code? | Excel Discussion (Misc queries) | |||
Self Destructing Spreadsheet | Excel Discussion (Misc queries) | |||
Drop Down/List w/Code and Definition, only code entered when selec | Excel Worksheet Functions | |||
stubborn Excel crash when editing code with code, one solution | Excel Programming |