打开VC,选择菜单(文件),新建,选择macro file,起个名字,确定
输入如下代码:
'------------------------------------------------------------------------------
'FILE DESCRIPTION: 为开发环境添加批量注释或取消注释
'------------------------------------------------------------------------------
Sub SetSelNote()'过程SetSelNote用于将选中的文本成为注释
dim CurWin'当前获得的窗口
set CurWin=ActiveWindow
if CurWin.type<>"Text" then '判断当前窗口是否为文本窗口
MsgBox"当前窗口不是代码窗口"
else
NoteType="//"
BeginLine=ActiveDocument.Selection.TopLine
EndLine=ActiveDocument.Selection.BottomLine
if EndLine<BeginLine then
Line=BeginLine
BeginLine=EndLine
EndLine=Line
else
for row=BeginLine To EndLine
ActiveDocument.Selection.GoToLine row
ActiveDocument.Selection.SelectLine'选中当前行
ActiveDocument.Selection=NoteType+ActiveDocument.Selection
Next
End if
End if
End Sub
Sub CancelSelNote()
dim CurWin'当前获得的窗口
set CurWin=ActiveWindow
if CurWin.type<>"Text" then '判断当前窗口是否为文本窗口
MsgBox"当前窗口不是代码窗口"
else
BeginLine=ActiveDocument.Selection.TopLine
EndLine=ActiveDocument.Selection.BottomLine
if EndLine<BeginLine then
Line=BeginLine
BeginLine=EndLine
EndLine=Line
else
for row=BeginLine To EndLine
ActiveDocument.Selection.GoToLine row
ActiveDocument.Selection.SelectLine'选中当前行
SelBlock=ActiveDocument.Selection
Trim(SelBlock)
pos=instr(SelBlock,"//")
if pos<>0 then
RightBlock=Right(SelBlock,Len(SelBlock)-2)
ActiveDocument.Selection=RightBlock
End if
Next
End if
End if
End Sub
然后保存
选择菜单(工具),定制,附加项和宏文件,浏览,找到刚才的宏文件,打开
换到命令选项卡,在类别下选择macros在右边即可看到刚才的宏命令,即可添加到工具栏内,成为工具条
Tools ->Customize
选中 Toolbar 1、2、3 就可以了 菜单上面立马显示出来
使用时选中然后按工具栏相应按钮即可。