【VC6.0】多行注释和反注释的方法

新建宏文件,贴代码:
'多行注释
Sub Comment()
 if Documents.Count = 0 then
  exit sub
 end if  
     lTopLine = ActiveDocument.Selection.TopLine
 lBottomLine = ActiveDocument.Selection.BottomLine
 lInsertPoint = ActiveDocument.Selection.CurrentLine
For I = lTopLine To lBottomLine
  ActiveDocument.Selection.MoveTo I, 1
  ActiveDocument.Selection.SelectLine
  s = ActiveDocument.Selection.Text
  if s <> vbCrLf then
   s = "//" + vbTab + s
  end if
  ActiveDocument.Selection.Text = s
 Next
if lTopLine = lInsertPoint then
  ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine
  ActiveDocument.Selection.MoveTo lTopLine, 1, dsExtend
 else
  ActiveDocument.Selection.MoveTo lTopLine, 1
  ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine, dsExtend
 end if

End Sub
'多行反注释
Sub Uncomment()
 if Documents.Count = 0 then
  exit sub
 end if 

 lTopLine = ActiveDocument.Selection.TopLine
 lBottomLine =ActiveDocument.Selection.BottomLine
 lInsertPoint = ActiveDocument.Selection.CurrentLine
For I = lTopLine To lBottomLine
  ActiveDocument.Selection.MoveTo I, 1
  ActiveDocument.Selection.SelectLine
  s = ActiveDocument.Selection.Text
  while left(s, 1) = " " OR left(s, 1) = vbTab
   s = right(s, len(s) - 1)
  Wend
if left(s, 3) = "//" + vbTab then
   s = right(s, len(s) - 3)
  elseif left(s, 2) = "//" then
   s = right(s, len(s) - 2)
  end if

  ActiveDocument.Selection.Text = s 
 Next
if lTopLine = lInsertPoint then
  ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine
  ActiveDocument.Selection.MoveTo lTopLine, 1, dsExtend
 else
  ActiveDocument.Selection.MoveTo lTopLine, 1
  ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine, dsExtend
 end if

 ActiveDocument.Selection.SmartFormat
End Sub
关闭并保存。
工具-->定制-->附加项和宏文件-->浏览-->选择刚才创建的宏文件-->打上√-->命令-->在类别中选择macros-->在右侧命令中拖出刚才生成的两个宏名(comment和Uncomment)到工具条上-->分别选择图标。
设置快捷键:键盘-->类别中选择Macros,在命令中选择comment或Uncomment然后设置快捷键即可。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值