Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I Comment Out a large portion of VBA Code? 13

Status
Not open for further replies.

alexyo7

Programmer
Jan 26, 2004
7
US
How can I "comment out" a large portion of VBA code? There's got to be an easier way than putting a single quote in front of each line. Thanks!
 
Unlike the 'real' Visual Basic, VBA does not have the capability to mark a chunk of code as comment.


Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Actually, under Access-XP there is an Edit menu when code is displayed. One of those options is to mark code as comment enmass. htwh,

Steve Medvid
"IT Consultant & Web Master"

Chester County, PA Residents
Please Show Your Support...
 
>does not have the capability to mark a chunk of code as comment.


Maybe not in your version for some reason, but it's been possible in the various Office VBAs for years...
 
If it's a big chunk, I often use conditional compile to comment out a bunch of stuff. That way it doesn't even have to refer to legit variables and objects, or have legit syntax event. Just do like this:

#if 1 = 2 then
look, ma, no comment symbol, and no error on compile
#end if

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
I've never seen a need for conditional compiler statements before, but that's one I'll use in the future!

have a start Jeremy.

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
 
For the Masters of the Access Universe

I always keep the Edit Toolbar visible in the Code Window. It has the Comment and Uncomment block buttons which do the same but in a very handy way :)
Like Visual Basic :-D


This is not available as Menu in Access 2K. i don't understand Microsoft at all at times

Like Steve Medvid commented, it is available in Xp

Best of luck


 
Hi Jeremy,

Star from me too. That's so delightfully simple.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Jeremy:

That's a keeper. Thanks.

Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
Jeremy:

That was wonderful for its simplicity. Here's a star.

RiderJon
"I might have created ctrl+alt+del,
But Bill made it famous" - Dr. Dave
 
Thanks Jeremy for an excellent answer to what should not even have to be asked. For all the things Access/VBA can do... To not be able to comment out large portions of code in the bat of eye is absurd.

Thanks to alexyo7 for asking a question that I thought was just to simple to ask, thought I would just get blown off the board with a simple duh?

Thanks again guys.

John
 
It's great that this has made so many people happy. I remember when I learned this I was in the middle of testing a bunch of code, and it was hugely helpful. I don't seem to use it much lately, but it is nice to know of.

Thanks for the thanks, folks.

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Another way to do this is:

[blue]GoTo 2[/blue]
--
---code
----code
---code
--
[blue]2[/blue]

It'll skip all other lines and start from the line that says 2.
 
Excelent Q and excelent A's
Thx 13badar The GoTo statement is an overlooked gem in my book ;-)

Herman

They say that crime doesn't pay... does that mean my job is a crime?
 
Hi 13badar,

Using a GoTo to skip code does not cause the intervening code to be commented out. It must still be valid code and will still be compiled - it may still get executed if it contains labels or line numbers which other code branches to - something which would be thrown up as a compile error if the code were actually commented out. It can be a useful technique but it doesn't comment out code, which was the original question.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Geoff:

Perfect. The two buttons are now firmly ensconced on my tool bar.

Thanks.

Larry De Laruelle

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top