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中选择一个然后设置快捷键即可。

  • 相关阅读:
    【转】软链接和硬链接到底有啥作用和区别
    useradd命令详解
    【转】Linux下MySQL数据库安装及配置方法
    【转】MySQL的安装与配置——详细教程-window系统下
    mysql服务器常用命令
    【转】DDL/DML/DCL区别概述
    tmux终端工具的简单使用
    linux go环境安装和基本项目结构
    ClickHouse高可用集群的配置
    centos7下使用rpm包安装clickhouse
  • 原文地址:https://www.cnblogs.com/hbhzz/p/3369038.html
Copyright © 2011-2022 走看看