zoukankan      html  css  js  c++  java
  • 利用VBA 宏实现vc6.0的自动添加注释和自动取消注释

    虽然一下方法可以实现,但是安装 Visual_Assist_X_10.7.1925.0 后可以自动实现这些功能,而且感知比较好,建议使用助手工具而不是以下的方法。

    Tools-->Macro-->输入Macro Name-->Edit-->Description-->点击OK,删除刚才生成的代码,贴代码:

    '多行注释
    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
    关闭并保存。
    Tools-->Customize-->Commands-->在Category中选择Marcos-->在右侧Commands中拖出刚才生成的两个宏名到工具条上,-->分别选择Images图标。
    设置快捷键:Keyboard-->Category中选择Macros,在Commands中选择一个然后设置快捷键即可。

  • 相关阅读:
    linq判断集合是否为空的方法
    MVC控制器取参数值
    linq查询结果转换为指定字段类型的list集合
    C#Web异步操作封装
    js基础细节
    写入临时日志到文本
    css3超过指定宽度文字,显示省略号
    如何判断Javascript对象是否存在
    chrome下input[type=text]的placeholder不垂直居中的问题解决
    sqlserver临时表操作
  • 原文地址:https://www.cnblogs.com/hbhzz/p/3369038.html
Copyright © 2011-2022 走看看