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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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