Where do you want F5 to go today

VSTO 2.0 has an interesting feature that lets you decide whether Visual Studio or Excel/Word handle accelerator keys you press (like F5).

Because of VSTO 2.0’s feature where the Excel document opens inside of the Visual Studio frame, there is some potential ambiguity around what F5 means.  If you press F5 in stand-alone Excel, it brings up Excel’s “Go To” dialog.  But if you press F5 when the Excel window is active inside of the Visual Studio frame, you probably expect this to run the active Visual Studio project rather than bring up Excel’s “Go To” dialog.

To resolve this issue, by default VSTO routes all function keys and accelerators (like Ctrl+S) to Visual Studio first.  If Visual Studio doesn’t recognize the function key or accelerator, we route the command to Excel or Word second.  This makes it so a command like F5 is handled by Visual Studio–when you press F5 for a VSTO 2.0 Excel project where the Excel document surface is active, Visual Studio runs the project.

You can control whether Visual Studio or Excel/Word handle accelerator keys first.  There is a button on the far left of the toolbar that is shown when an Excel or Word document surface is active within Visual Studio.  If you click on this button, you can toggle whether Visual Studio or Excel/Word gets the accelerators first.  So if you want F5 to bring up the “Go To” dialog rather than run the project, you can toggle this setting and F5 will be handled by Excel/Word first and Visual Studio second (if Excel or Word doesn’t have the function key or accelerator mapped to a command).

Comments (0)