Sheets changing name
Hi there again Oldjay,
Firstly when you use the code to disable alerts dont forget to turn the
alerts back on at the end of the sub with the following.
Application.DisplayAlerts = True
The automation error is caused by deleting the worksheet that has the code
in it. When you are copying the worksheet, both the command button and the
code that goes with it are copied into the new worksheet and in fact you will
have multiple copies of the code; one copy in each worksheet. If you run the
code from a worksheet that is being deleted, the code associated with it gets
deleted also. If you run it from the master worksheet then you will not get
the error.
Having said that, there is a better way of arranging your code and calling
that code when you are copying worksheets. I know I previously said to put
the main code in a standard module and just call that code with the code
associated with a command button. However, now that you have introduced
deleting worksheets, I think the following method is preferable.
Instead of using the ActiveX command buttons from the Control Toolbox
toolbar, use the Button from the Forms toolbar. This way all of your code
goes into a standard module and you can name the subs whatever you like and
after creating the button from the Forms toolbar, you will get a dialog box
to assign a macro to it. (Later if you need to get back to the dialog box,
right click the button). Then when you copy a worksheet, only the button gets
copied and no additional copies of the code are made. The button on every
worksheet calls the same code in the standard module. You can run the delete
sheet code from any worksheet because the code never gets deleted.
If you use my suggested method, dont forget to delete the code in the
Master worksheet.
--
Regards,
OssieMac
|