Macros in Visual Studio (BIDS)

This post is an extended version of a question I answered on Stack Overflow because it was interesting. When I think of Macros on the one hand I recall quite complicated VBA workbooks I’ve done in the past and on the other hand basic keyboard shortcuts e.g. on programmable mice for fast gaming purposes.


Usually with shortcuts in Visual Studio (BIDS), you can go Tools –> Options –> Environment –> Keyboard

If you filter the list of commands to make the list shorter, you can find the command you want and click into the “Press shortcut keys:” text box and then press the shortcut combination you want.

I tried that and everything related to Expression didn’t work 🙁 . Basically it’s pretty hard to know what all those commands are and hard to find the one you want.

But there’s another option. It’s a bit round-a-bout but it works fine. It basically involves creating a macro which will send shift-F10-E to your active context and then binding that macro to your shortcut keys of choice, e.g. CTRL-1. I’m using Visual Studio 2008 (installed from SQL Server 2008R2 disk)

1) Show the macro window by selecting View–> Other windows –> Macro Explorer

2) Create a new module under “MyMacros”

3) Enter this VB.NET code:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module UserShortcuts
    Public Sub ShowExpression()
    End Sub
End Module

4) Go to Tools –> Options –> Environment –> Keyboard

5) Type “macros” into the “Show commands containing:” textbox and the sub as defined in the module in the code above will appear and you can highlight it.

VS Macro key bind dialog

6) You can then select the “Press shortcut keys” textbox and type [CTRL] + 1 or whatever you like and then click the [Assign] button.

7)  This MSDN page shows all the key options you can choose for the SendWait method. If you want to add more keyboard shortcuts, just add more Sub() entries in the module for each one and then map them as per steps 4 to 6.

Leave a Reply

Your email address will not be published. Required fields are marked *