Reputation: 12037
In the VBA editor of Office (ALT + F11), how do you comment or uncomment a block of code?
Upvotes: 347
Views: 789391
Reputation: 2125
&
) to the beginning of the entry. Upvotes: 200
Reputation: 45
After adding the icon to the toolbar and when modifying the selected icon, the ampersand in the name input is specifying that the next character is the character used along with Alt for the shortcut. Since you must select a display option from the Modify Selection drop down menu that includes displaying the text, you could also write &C in the name field and get the same result as &Comment Block (without the lengthy text).
Upvotes: 3
Reputation: 11
Steps to comment / uncommented
Press alt + f11/ Developer tab visual basic editor view tab - toolbar - edit - comments.
Upvotes: 1
Reputation: 2289
There is a built-in Edit toolbar in the VBA editor that has the Comment Block and Uncomment Block buttons by default, and other useful tools.
If you right-click any toolbar or menu (or go to the View menu > Toolbars), you will see a list of available toolbars (above the "Customize..." option). The Standard toolbar is selected by default. Select the Edit toolbar and the new toolbar will appear, with the Comment Block buttons in the middle.
*This is a simpler option to the ones mentioned.
Upvotes: 49
Reputation: 12037
In the VBA editor, go to View
, Toolbars
, Customise...
or right click on the tool bar and select Customise...
Under the Commands
tab, select the Edit
menu on the left.
Then approximately two thirds of the way down there's two icons, Comment Block
and Uncomment Block
.
Drag and drop these onto your toolbar and then you have easy access to highlight a block of code, and comment it out and uncomment with the click of a button!
See GauravSingh's answer if you want to assign keyboard shortcuts.
Upvotes: 564
Reputation: 1155
Or just click View, ToolBars, Edit. Then you can select a block of code and then click the Comment or Uncomment toolbar button to do everything in one click.
As an aside, you can Tab/Shift+Tab a block of selected text also. When I was a noobie, I didn't know that for a long time and would do them one line at a time.
Good Luck!
Upvotes: 4
Reputation: 20760
An easy way to add buttons to Comment
or Un-Comment
a code block is:
Upvotes: 1
Reputation: 2097
Have you checked MZTools?? It does a lot of cool stuff...
If I'm not wrong, one of the functionalities it offers is to set your own shortcuts.
Upvotes: 20