45

In VBA is there a short way to comment out a block of code the same way java uses /*...*/?

2
  • 4
    Yes and it's called "Comment Block" AND, it may not be present on your toolbar. If not, right click a toolbar in the VBE and choose "Customize". On the Commands tab, choose "Edit" and scroll down the Commands list until you find it. Drag to a toolbar. Do the same for the "Uncomment Block" icon from here Commented Jun 2, 2014 at 19:08
  • stackoverflow.com/a/12933280/3198973 Commented Jun 2, 2014 at 19:11

3 Answers 3

80

Although there isn't a syntax, you can still get close by using the built-in block comment buttons:

If you're not viewing the Edit toolbar already, right-click on the toolbar and enable the Edit toolbar:

enter image description here

Then, select a block of code and hit the "Comment Block" button; or if it's already commented out, use the "Uncomment Block" button:

enter image description here

Fast and easy!

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much for also including how to show the edit toolbar where the function can be found. Little things like that can be so helpful!
9

prefix the comment with a single-quote. there is no need for an "end" tag.

'this is a comment 

Extend to multiple lines using the line-continuation character, _:

'this is a multi-line _ comment 

This is an option in the toolbar to select a line(s) of code and comment/uncomment:

enter image description here

12 Comments

This works but I am looking for something i can put at the end and at the start of an already existing block of code rather than something on every line.
Doesn't exist the way you want it @Tim.DeVries.
@Tim.DeVries there is no such functionality in VBA. Your best alternative is to simply use the cursor to select multiple lines of code and press the button for "Comment Block" from the menu bar. There is no syntax that does this.
Curious why you'd un-accept my answer (two weeks later!) in favor of a nearly-identical answer that was posted ~2 hours after mine... I have no need for the karma here, I'm just trying to find out why this answer is not good for you now, when it was originally...
@DavidZemens That's just because you're missing beans.dll
|
5

There is no syntax for block quote in VBA. The work around is to use the button to quickly block or unblock multiple lines of code.

1 Comment

This answer doesn't add anything to the accepted answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.