vba code to update vba code in Thisworkbook

Doug Mutzig

Board Regular
Joined
Jan 1, 2019
Messages
57
Office Version
  1. 365
Platform
  1. Windows
Good afternoon all!

I am working on a workbook where I have been asked to lock down or turn off a lot of items (formula bar, ribbon, headings, tabs, copy/paste, dragging, etc.). I have this working but I have had to go back and do edits and other updates as changes are requested which causes a bit of a headache to manually go into vba > thisworkbook, and comment out everything, and then repeat the process to uncomment it all again. I was wondering if there is a way I could have a button on a hidden page that would run a macro to add/remove the comment " ' " from specific lines?

An example is:
Code:
Option Explicit
 
Private Sub Workbook_Open()
 
'Protect workbook structure, tabs, and worksheets
    'ThisWorkbook.Protect Password:="test", Structure:=True, Windows:=True
 
    Application.ScreenUpdating = False
 
'Turn off Formulabar, Tabs, Column & row headings, Ribbon, Drag&Drop, copy&paste, Ribbon, right-click menu
    'Application.DisplayFormulaBar = False
    'ActiveWindow.DisplayWorkbookTabs = False
    'ActiveWindow.DisplayHeadings = False
    'Application.CellDragAndDrop = False
    'Application.CutCopyMode = False
    'Application.OnKey "^c", ""
    'Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
       
'Turn off some error checking
    'Application.ErrorCheckingOptions.BackgroundChecking = False
   
   
'Go to the Index tab when opening
    Sheets("INDEX").Select
    Range("S6").Select
   
    MsgBox ("Workbook ready for editing" & vbNewLine & "Click OK to continue")
   
    Application.ScreenUpdating = True
End Sub
Private Sub Workbook_Activate()
 
    Application.ScreenUpdating = False
   
'Turns off items when clicking back on the workbook from a different application/workbook
    'Application.DisplayFormulaBar = False
    'ActiveWindow.DisplayWorkbookTabs = False
    'ActiveWindow.DisplayHeadings = False
    'Application.CellDragAndDrop = False
    'Application.CutCopyMode = False
    'Application.OnKey "^c", ""
    'Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
   
'Turns off some error checking
    'Application.ErrorCheckingOptions.BackgroundChecking = False
   
    Application.ScreenUpdating = True
       
End Sub

You can see where the "False" lines are currently commented out so that I can work without everything turned off. Is there a way to create a macro to remove the comments from the lines and then another button to add them? I tried using the macro recorder but it doesn't seem to record vba steps.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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