这里所说的宏是指通过一系列键盘组合键和可以插入自定义内容。下面介绍怎么编写一个自己的宏:
1、在Visual Studio 2010中按Alt+F11打开宏IDE:
2、打开后选择添加模块:
3、在弹出的窗口中输入名称后确定添加:
4、出现如下页面即可进行编辑:
5、在Public Module MyInformation中添加如下代码:
1 Public Sub FileSign() 2 Dim DocSel As EnvDTE.TextSelection 3 DocSel = DTE.ActiveDocument.Selection 4 DTE.ActiveDocument.Selection.StartOfDocument() 5 DocSel.NewLine() 6 DocSel.Text = "/*============================================================================" 7 DocSel.NewLine() 8 DocSel.Text = "* Author : " 9 DocSel.NewLine() 10 DocSel.Text = "* Mail : " 11 DocSel.NewLine() 12 DocSel.Text = "* Last modified : " + Date.Today.ToString("yyyy-MM-dd") + " " + TimeOfDay.Hour.ToString("00") + ":" + TimeOfDay.Minute.ToString("00") 13 DocSel.NewLine() 14 DocSel.Text = "* Filename : " + DTE.ActiveDocument.Name 15 DocSel.NewLine() 16 DocSel.Text = "* Description :" 17 DocSel.NewLine() 18 DocSel.Text = "*" 19 DocSel.NewLine() 20 DocSel.Text = "============================================================================*/" 21 DocSel.NewLine() 22 End Sub
添加完成后保存:
6、保存后可以关闭宏IDE,进入Visual Studio 2010主界面—>工具—>选项—>环境—>键盘项,进入如下页面:
7、接着可以为刚才编写的宏映射键盘快捷键:
输入快捷键后,点击分配按钮,若快捷键没有被占用则下面的“快捷键的当前使用对象”框内容为空,可以点击确定完成宏的映射设置;
8、完成后,即可验证本次宏的编写是否正确。
附:
(1)部分图片引用自CSDN郗晓勇的博客:http://blog.csdn.net/beijiguangyong/article/details/6371504
(2)MSDN中关于宏的一些介绍:http://msdn.microsoft.com/zh-cn/library/b4c73967(v=vs.100).aspx
VS2010中编写宏添加作者信息,布布扣,bubuko.com
原文:http://www.cnblogs.com/vitah/p/3690442.html