Microsoft 9GD00001 Computer Accessories User Manual


 
370 Microsoft Visual Studio 2010: A Beginner’s Guide
' Logic to add product
Return newProdID
End Function
End Class
To fix the problem with the macro (for the C# code) opening the Customer.cs file,
notice that the macro has three statements that activate the Customer.cs file. Comment out
each of these statements as shown in the following excerpt:
'DTE.Windows.Item("Customer.cs").Activate()
'DTE.Windows.Item("Customer.cs").Activate()
DTE.Find.FindWhat = "{"
'DTE.Windows.Item("Customer.cs").Activate()
If you were to write your own macro via code, a quick way to figure out what code
you have to write is to start the macro recorder in VS (
CTRL-SHIFT-R), use the VS feature
you want to code, stop recording (
CTRL-SHIFT-R), and save the macro. Then inspect the code
in the Macro editor and copy the parts you need. This technique is especially valuable to
figure out how to open windows, such as the Find And Replace window discussed in the
preceding paragraph. For even more help, there are several example macros under the
Samples folder, shown in Figure 12-9, showing you different ways to write VS macros.
Summary
Now you know about various techniques for customizing VS. You learned how to customize
projects and save your work as a custom project template. In a related task, you saw how
you can create a new file and then save that file as a custom item template. This gives you
the ability to use projects and project items in a way that you want. In addition to using
snippets that ship with VS, you learned how to find the definition of existing snippets and
either modify a snippet or create a brand new snippet from scratch. You also saw how to
organize snippets with the Snippets Manager. Finally, you learned how to record and save
repeatable actions with VS macros. You can also use the Macro editor to customize existing
macros or create new ones on your own.
Macros are very powerful, but VS has even more capabilities for allowing you to
extend the IDE. You’ll learn how to extend VS by writing Add-Ins in the next chapter.