﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » Updates and Information » StrataFrame Users Contributed Samples  » Fun with Macros</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 03:38:12 GMT</lastBuildDate><ttl>20</ttl><item><title>Fun with Macros</title><link>http://forum.strataframe.net/FindPost15697.aspx</link><description>In VFP I enjoyed the comment / uncomment right click menu option for blocks of code.&amp;nbsp; The closest I've been able to find in the VB 2008 IDE is a macro sample to comment and nothing to uncomment.&amp;nbsp; Soooo, this may be old hat to experienced VS users but if you're a newbie like me you may find this useful :&lt;P&gt;Tools / Customize / Macros&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/dae1e85b-6b1e-4005-8877-c304.jpg"&gt;&lt;/P&gt;&lt;P&gt;Now you can drag that Samples.VSEditor.CommentRegion right onto a toolbar.&amp;nbsp; Then, with the Customize dialog still open, right click on what you dragged onto the bar and select Default Style&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/46b601f1-0fbf-46fb-b62a-e859.jpg"&gt;&lt;/P&gt;&lt;P&gt;Which will reduce it to a blank icon and then pick Chang Button Image to give it an icon.&lt;/P&gt;&lt;P&gt;Okay, now if you hightlight a block of text in code it will all be commented out with single quotes&lt;/P&gt;&lt;P&gt;But what of uncommenting ?&lt;/P&gt;&lt;P&gt;I wrote this macro which you can paste into the macro file that comes up when you open the Macros IDE ( you can drag that out of Tools in customize and onto a menu )&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; UncommentBlock()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; current &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;current = DTE.Active&amp;#100;ocument.Name&lt;/P&gt;&lt;P&gt;DTE.ExecuteCommand(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"Edit.Find"&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;DTE.ExecuteCommand(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"Edit.SwitchtoQuickReplace"&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;DTE.ExecuteCommand(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"Edit.SelectAll"&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;DTE.Windows.Item(current).Activate()&lt;/P&gt;&lt;P&gt;DTE.Find.FindWhat = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"'"&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;DTE.Find.ReplaceWith = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;""&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocumentSelection&lt;/P&gt;&lt;P&gt;DTE.Find.MatchCase = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;False&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;DTE.Find.MatchWholeWord = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;False&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;DTE.Find.MatchInHiddenText = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;True&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral&lt;/P&gt;&lt;P&gt;DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone&lt;/P&gt;&lt;P&gt;DTE.Find.Action = vsFindAction.vsFindActionReplaceAll&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/FONT&gt;&lt;FONT size=2&gt; (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Throw&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;New&lt;/FONT&gt;&lt;FONT size=2&gt; System.Exception(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"vsFindResultNotFound"&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;DTE.Windows.Item(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"{CF2DDC32-8CAD-11D2-9302-005345000000}"&lt;/FONT&gt;&lt;FONT size=2&gt;).Close()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]&lt;/P&gt;&lt;P&gt;Just does a search and replace for ' inside a highlighted block&lt;/P&gt;&lt;P&gt;As soon as you save the macro file, you'll find that one the same place you found the CommentRegion() and you can put it on a toolbar the same way.&lt;/P&gt;&lt;P&gt;I'll put the tasklist thing in a separate message.</description><pubDate>Fri, 18 Apr 2008 12:09:13 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Fun with Macros</title><link>http://forum.strataframe.net/FindPost15764.aspx</link><description>[quote]Goes along with my life maxim that most of the valuable stuff I know I learned on my way to looking up something else :)[/quote]&lt;br&gt;
&lt;br&gt;
Ahmen! And I learned a lot about marcos from your example :D</description><pubDate>Fri, 18 Apr 2008 12:09:13 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Fun with Macros</title><link>http://forum.strataframe.net/FindPost15757.aspx</link><description>Hey, thanks for the links Charles. ;)</description><pubDate>Fri, 18 Apr 2008 08:37:56 GMT</pubDate><dc:creator>Ivan George Borges</dc:creator></item><item><title>RE: Fun with Macros</title><link>http://forum.strataframe.net/FindPost15754.aspx</link><description>gotta remember to google !!!&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.msdn.com/vbteam/archive/2007/04/24/save-time-use-keyboard-shortcuts-lisa-feigenbaum.aspx"&gt;http://blogs.msdn.com/vbteam/archive/2007/04/24/save-time-use-keyboard-shortcuts-lisa-feigenbaum.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=6bb41456-9378-4746-b502-b4c5f7182203&amp;amp;DisplayLang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyID=6bb41456-9378-4746-b502-b4c5f7182203&amp;amp;DisplayLang=en&lt;/A&gt;</description><pubDate>Thu, 17 Apr 2008 22:37:38 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Fun with Macros</title><link>http://forum.strataframe.net/FindPost15753.aspx</link><description>[quote]Do you know about the keyboard shortcuts?[/quote]&lt;/P&gt;&lt;P&gt;Obviously no :blush:&lt;/P&gt;&lt;P&gt;Seemed like there should be something like that but darned if I could find them ( where shoulld I have been looking to find a list of such shortcuts? )&lt;/P&gt;&lt;P&gt;Oh well, learned a lot of cool stuff about macros along the way.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Goes along with my life maxim that most of the valuable stuff I know I learned on my way to looking up something else :)</description><pubDate>Thu, 17 Apr 2008 22:27:02 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item><item><title>RE: Fun with Macros</title><link>http://forum.strataframe.net/FindPost15724.aspx</link><description>[quote]&lt;SPAN id=ctl02_ctlTopic_ctlPanelBar_ctlTopicsRepeater_ctl06_lblFullMessage&gt;Do you know about the keyboard shortcuts?&lt;BR&gt;&lt;BR&gt;Highlight the code desired and then&lt;BR&gt;Ctl +k+c to comment&lt;BR&gt;Ctl +k+u to uncomment&lt;/SPAN&gt; [/quote]&lt;/P&gt;&lt;P&gt;Very close and personal friends :D</description><pubDate>Thu, 17 Apr 2008 08:17:52 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Fun with Macros</title><link>http://forum.strataframe.net/FindPost15718.aspx</link><description>Do you know about the keyboard shortcuts?&lt;br&gt;
&lt;br&gt;
Highlight the code desired and then&lt;br&gt;
Ctl +k+c to comment&lt;br&gt;
Ctl +k+u to uncomment</description><pubDate>Wed, 16 Apr 2008 23:06:08 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Fun with Macros</title><link>http://forum.strataframe.net/FindPost15699.aspx</link><description>And here's the comment / task list token macro :&lt;P&gt;[codesnippet]&lt;/P&gt;&lt;P&gt;'And you can customize this even further by using YOUR initials instead of mine :-) &lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; InsertCRH()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; textSelection &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; EnvDTE.TextSelection&lt;/P&gt;&lt;P&gt;textSelection = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;CType&lt;/FONT&gt;&lt;FONT size=2&gt;(DTE.Active&amp;#100;ocument.Selection(), EnvDTE.TextSelection)&lt;/P&gt;&lt;P&gt;textSelection.Text = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"' CRH: "&lt;/FONT&gt;&lt;FONT size=2&gt; &amp;amp; System.DateTime.Now.ToString() &amp;amp; CrLf _&lt;/P&gt;&lt;P&gt;&amp;amp; &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"' "&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]&lt;/P&gt;&lt;P&gt;See prior message for putting it on a toolbar and my message about snippets in General .NET section to see about the method and reasons to put your initials into a task list token&lt;/P&gt;&lt;P&gt;Charles</description><pubDate>Wed, 16 Apr 2008 13:35:15 GMT</pubDate><dc:creator>Charles R Hankey</dc:creator></item></channel></rss>