这里所说的宏是指通过一系列键盘组合键和可以插入自定义内容。下面介绍怎么编写一个自己的宏:

1、在Visual Studio 2010中按Alt+F11打开宏IDE:

VS2010中编写宏添加作者信息与函数注释

 

2、打开后选择添加模块:

VS2010中编写宏添加作者信息与函数注释

 

3、在弹出的窗口中输入名称后确定添加:

VS2010中编写宏添加作者信息与函数注释

 

4、出现如下页面即可进行编辑:

VS2010中编写宏添加作者信息与函数注释

 

5、在Public Module MyInformation中添加如下代码:

(1)FileSign函数:添加作者信息

 1 Public Sub FileSign()
 2         Dim DocSel As EnvDTE.TextSelection
 3         DocSel = DTE.ActiveDocument.Selection
 4 
 5         '活动点移到文件开头
 6         DTE.ActiveDocument.Selection.StartOfDocument()
 7 
 8         If DocSel.FindPattern("Last modified", vsFindOptions.vsFindOptionsRegularExpression) Then
 9             '找到Last modified字符串,说明已经添加过作者信息,只更新Last modified和Filename信息
10             DocSel.SelectLine()
11             DocSel.Delete()
12             DocSel.SelectLine()
13             DocSel.Delete()
14             DocSel.Text = "//  Last modified : " + Date.Today.ToString("yyyy-MM-dd") + " " + TimeOfDay.Hour.ToString("00") + ":" + TimeOfDay.Minute.ToString("00")
15             DocSel.NewLine()
16             DocSel.Text = "//  Filename      : " + DTE.ActiveDocument.Name
17             DocSel.NewLine()
18         Else
19             '没有找到Last modified字符串,添加全部信息
20             DTE.ActiveDocument.Selection.StartOfDocument()
21             DocSel.Text = "//=================================================================="
22             DocSel.NewLine()
23             DocSel.Text = "//  Author        : vitah"
24             DocSel.NewLine()
25             DocSel.Text = "//  Mail          : linw1225@163.com"
26             DocSel.NewLine()
27             DocSel.Text = "//  Last modified : " + Date.Today.ToString("yyyy-MM-dd") + " " + TimeOfDay.Hour.ToString("00") + ":" + TimeOfDay.Minute.ToString("00")
28             DocSel.NewLine()
29             DocSel.Text = "//  Filename      : " + DTE.ActiveDocument.Name
30             DocSel.NewLine()
31             DocSel.Text = "//  Description   :"
32             DocSel.NewLine()
33             DocSel.Text = "//"
34             DocSel.NewLine()
35             DocSel.Text = "//=================================================================="
36             DocSel.NewLine()
37             DocSel.NewLine()
38         End If
39 
40         DocSel.MoveToLineAndOffset(7, 5)  '活动点移动到Description处,填写描述信息
41     End Sub
FileSign

相关文章:

  • 2022-12-23
  • 2021-06-12
  • 2022-01-07
猜你喜欢
  • 2021-04-04
  • 2022-12-23
  • 2021-07-29
  • 2021-04-10
  • 2021-07-08
  • 2022-12-23
  • 2021-09-01
相关资源
相似解决方案