22-06-2022 - Disable Ctrl+W in Excel

Mission:

While working with iFIX you get used to hit the combination Ctrl+W to start and stop the workspace.
If a second screen is opened with Excel, you close the workbook in Excel if you are on the wrong screen.

Solution:

VBA is your friend. Sit and relax.

Step 1 - Enable the developer tab.

1. On the File tab, go to Options > Customize Ribbon.
2. Under Customize the Ribbon and under Main Tabs, select the Developer check box.

Step 2 - Enter a macro that runs automatically while opening the workbook.

1. Open the workbook.
2. Goto the Developer tab.
3. Hit the Visual Basic button.
4. In the VBA Project Explorer on the left hand side, expand the VBA Project folder of the workbook.
5. Double click the ThisWorkbook module.
6. In the module window that opens, enter the following code:
      Private Sub Workbook_Open()
      ' Disable CTRL+W (close workbook)
      Application.OnKey "^w",""
      Application.OnKey "^W",""
      End Sub
7. Save and exit. (save as .xslm)

Back to top