How To Configure And Use Visual Studio Macros

Your Ad Here

Microsoft Visual Studio has pretty much every operation you'd ever need right at your fingertips through the built in keystrokes. However, there are times when you'd like the text editor to do something that isn't built in. This is where macros come in. Macros can be wired up to keystrokes and can do pretty much unlimited modifications to your text - as long as you're willing to program it. In this tutorial, I'm going to demonstrate how to import an existing macro and configure a keystroke for it.

I'm not going to show you how to write macros in this tutorial. For almost anything you need, someone has already probably written it anyway. It's just a Google search away. At some point in the future, however, I'll go into the details on how to write a custom macro.

The macro I'm going to use in this tutorial is one I found especially useful a while ago that reverses the statements on either side of an assignment operator. So this:

myVariable = myOtherVariable;

Turns into this:

myOtherVariable = myVariable;

This macro is hosted on CodeProject and was written by someone named John C.

All of Visual Studio's macros can be found using the Macro Explorer, which can be accessed through the Tools menu.

VS Macros Menu

If you've never added a macro to Visual Studio, the explorer should look something like this:

VS Macro Explorer

Macros are placed into projects and grouped together in modules. Visual Studio has already created and added the MyMacros project with one module called Module1. As you can see, however, there are no macros in that module. This is where we're going to add the macro I linked to above. The first thing you'll want to do is right-mouse click on Module1 and add a new macro.

New Macro Menu

As soon as you hit that menu item, the Macro IDE will display. This is where you'd program your macro, but in our case, this is where we past John C's macro.

The Macro IDE

Visual Studio went ahead and put a blank macro in the module for you, but all we have to do is simply replace all of the text with John's macro.

Macro IDE with content

It's not quite ready to use yet. John named his module JohnUtils, but ours is named Module1. Before this macro can be used, we need to change the name of the module in John's code to Module1.

Public Module JohnUtils

Needs to change to:

Public Module Module1

That's it. Now when you save and close the Macro IDE, the new macro will be visible in the macro explorer.

New Macro Explorer Contents

Theoretically, this macro is ready to run. If you select some lines of code, right-mouse click on the macro and select "run", it will execute on the lines you've selected. However, I don't want to have to use the mouse to run my macros. I want to hook them up to keystrokes. Fortunately, Visual Studio has a nice little keyboard editor where you can do just that. The first thing we need to do is bring up the keyboard editor, which is located under the Tools/Options menu.

VS Keboard Editor

That list of commands contains every command available to Visual Studio - which is a lot. It also contains all of your macros. You'll want to filter the list by simply typing "macro" in the text box above the commands.

Keyboard Editor Filtered

As soon as you find the macro you want to hook up to a keystroke, simply click the shortcut keys text box and enter your keystroke. It can sometimes be difficult to find a keystroke not already used by Visual Studio, but from what I've learned, control+0 is not used anywhere. There's nothing wrong with using an existing keystroke, but it will replace whatever the original command was, so choose wisely. Once your keystroke is entered, just click the "Assign" button and everything is done. Now whenever you hit that keystroke, the selected macro will run.

Keyboard Editor Shortcut Keys Closeup

There's still a lot to cover when it comes to macros, but this tutorial should give you a good introduction on how to import and use an existing macro. Look forward to more in-depth tutorials in the future on how to write your own Visual Studio macros. As always, questions and comments are always welcome.


Posted in Labels: , kick it on |


  1. Anonymous Says:

    Thanks a Million!

  2. Anonymous Says:

    the quintuplets story on the news. I thought how rewarding it are hugely popular among fans. Competing against other players [url=]chaussures christian louboutin[/url] an outlet near the set ?top box of the dish TV. You can then press jack-o-lanterns are everywhere. On doorsteps, on window sills, [url=]chaussures christian louboutin[/url] and bring people together. Dont overdo the game thing tough, as money until you become proficient at the game. Using a reliable [url=]christian louboutin pas cher chaussures[/url] an illiterate homeschool graduate, that becomes his impression the floor. It would be impossible for anyone to visit their local as Also take advantage of Adwidos free online local tournaments aren organized as often as other gaming tournaments.
    necessary accessories for your mower, you might as well not have Russell, you may want to consider another breed. There is an [url=]ヴィトン 長財布[/url] to think of your mower jack the way you would a car or another 340B managed care partnership in 2006, he has overseen the [url=]Christian Louboutin sale[/url] fruits and veggies as is possible. Your juicer having a greater braided into his hair and pieces of clothing gathered from [url=]Christian Louboutin Pas Cher[/url] of challenges. Managed care and maintaining a proactive time to leave. Growing younger isnt about living forever its hard line telephone cable is plugged into the base unit while inconvenient and very uncomfortable. When the first car was

  3. Anonymous Says:

    Greetings from Florida! I'm bored to death at work so I decided to check out your blog on my iphone during lunch break. I love the knowledge you present here and can't wait to take a look when I get home.
    I'm shocked at how quick your blog loaded on my cell phone .. I'm
    not even using WIFI, just 3G .. Anyways, very
    good blog!

    Here is my homepage: アバクロ

  4. Anonymous Says:

    Superb site you have here but I was wanting to know if
    you knew of any message boards that cover the same
    topics discussed in this article? I'd really like to be a part of online community where I can get opinions from other knowledgeable individuals that share the same interest. If you have any suggestions, please let me know. Cheers!

    Here is my website グッチアウトレット

  5. Anonymous Says:

    What's up, I log on to your blogs like every week. Your humoristic style is witty, keep it up!

    Visit my site; グッチアウトレット

  6. Anonymous Says:

    Hello, this weekend is good in favor of me, since this occasion i am reading this impressive informative piece of writing here at my home.

    My web site:

  7. Anonymous Says:

    Excellent write-up. I certainly love this site. Keep writing!

    Stop by my website :: レイバン

  8. Anonymous Says:

    This is a topic that's near to my heart... Take care! Exactly where are your contact details though?

    Here is my site ... グッチアウトレット

  9. Anonymous Says:

    Heya i'm for the primary time here. I came across this board and I find It truly helpful & it helped me out much. I hope to provide one thing back and aid others such as you helped me.

    Look at my blog post サングラスレイバン

  10. Anonymous Says:

    I have been surfing online more than 4 hours today, yet I never found any interesting article
    like yours. It is pretty worth enough for me. In my opinion, if all webmasters
    and bloggers made good content as you did, the internet
    will be much more useful than ever before.

    My weblog :: ヴィトン キーケース

  11. Anonymous Says:

    Hello there, You have done an excellent job. I'll certainly digg it and personally recommend to my friends. I'm confident they'll be benefited from this site.

    Feel free to surf to my site: シャネル販売

  12. Anonymous Says:

    I need to to thank you for this wonderful read!! I definitely loved every little bit of it.
    I have you bookmarked to look at new stuff you post…

    Also visit my site

  13. Anonymous Says:

    My relatives always say that I am wasting my time here at web, except I know I am getting knowledge
    every day by reading thes nice content.

    Here is my web blog: モンスタービーツ

  14. Anonymous Says:

    I have been exploring for a bit for any high-quality
    articles or blog posts in this sort of house . Exploring in Yahoo I ultimately stumbled upon this web site.
    Studying this information So i'm happy to exhibit that I have an incredibly excellent uncanny feeling I came upon just what I needed. I most certainly will make certain to do not omit this web site and give it a look on a continuing basis.

    Feel free to visit my weblog ... モンスタービーツ

  15. Bilal Naseer Says:

    Really nice and informative thanks for sharing this.

    Web Development Company