53.5. How to Develop a Macro

Developing a macro with programming code is an easy task. You just write your code and debug it and don't need to worry about compilation and other stuff. You may notice that macro development is easier in comparison with other development scenarios like developing an add-in or a Windows application.

However, macro development applies your knowledge in object-oriented programming by using concepts like classes, modules, and methods to build a macro.

You can even use user interface elements like Windows Forms in your macros. This isn't a common scenario, but it can be done easily. As with a normal project, you add a reference to Windows Forms assemblies in your macro project, then add Windows Forms to your project and load them in your code. However, here we won't get into details about this here.

The best way to understand the development process is by seeing an example. Here you see an example that is a built-in part of Visual Studio. The accessibility module located in the Samples macro project that comes with the default Visual Studio installation is a module that contains a few macros to improve the accessibility of the Visual Studio IDE by changing the size of fonts and their colors. The code for this module is shown here:

Imports EnvDTE Imports System Imports EnvDTE80 Imports System.Diagnostics Imports Microsoft.Win32 Public Module Accessibility Private Const fontSizeIncrement As Integer = 2 Private Const minimumSupportedEditorSize As Integer ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.