VC中为开发环境添加批量注释或取消注释(转)

打开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  就可以了  菜单上面立马显示出来

使用时选中然后按工具栏相应按钮即可。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值