Copy Sheet and clear macros contained in it

massivtre

New Member
Joined
Mar 2, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello All,

Looking for some VBA help here. I have a spreadsheet which contains a number of checklists. Each main checklist is in its own sheet. All of these sheets are hidden until the user clicks on the hyperlink on the "Home" sheet (main sheet always visible). The VBA code I use to hide the sheets is written into each sheet. When the required checklist sheet is unhidden - the user then gets the option to copy this sheet with a new name from cell B7 (all original checklists need to remain unedited). My issue - when I copy the sheet with a new name it also copies the code to hide the sheet. I don't want this code to be copied to the new sheet (so the new copied sheet is always visible) - How can I achieve this? Thanks
 

Attachments

  • copy.JPG
    copy.JPG
    119.4 KB · Views: 11
  • hide.JPG
    hide.JPG
    108.9 KB · Views: 11
  • home.JPG
    home.JPG
    104.9 KB · Views: 11

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Add this before your If statement:

VBA Code:
    With ThisWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule
        .DeleteLines 1, .CountOfLines
    End With
 
Upvote 0
Solution
This worked great! Thanks

Just had to remember to turn on "Trust access to the VBA project object model".
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top