Shortcut Key to Comment/Uncomment Blocks of Code in VBA
One thing that is conspicuously missing from the VBA IDE is a keyboard shortcut to comment and uncomment blocks of code.
The VBIDE does provide commands for commenting and uncommenting blocks of code, though. And by adding those commands to the menu bar, we can assign "accelerator" keys to make it easy to use the keyboard to trigger these two commands. "Accelerator" keys are the underlined letters in menu commands that you can use to massively boost your productivity for frequently used commands.
Follow the steps below to assign the following shortcut keys to comment and uncomment blocks of VBA code:
- [Alt] + [C]: comment code block
- [Alt] + [U]: uncomment code block
Step-by-Step: Adding Comment/Uncomment Block Shortcut Keys
- Enter Customize mode: View > Toolbars > Customize... ([Alt] + [V], [T], [C])
- Go to the "Commands" tab
- Go to the "Edit" category
- Scroll to "Comment Block" command in Commands list
- Click and drag "Comment Block" to the end of the toolbar
- Click and drag "Uncomment Block" to the end of the toolbar
- Right-click the "Comment Block" icon and set the name to "&Comment Block"
- Check the box next to "Image and Text"
- Repeat steps for "Uncomment Block" and set name to "&Uncomment Block"
You can now comment blocks of code with [Alt] + [C] and uncomment blocks with [Alt] + [U].