24,854
社区成员
发帖
与我相关
我的任务
分享
'------------------------------------------------------------------------------
'FILE DESCRIPTION: 为开发环境添加批量注释或取消注释
'------------------------------------------------------------------------------
Sub SetSelNote() 'Sun DESCRIPTION : 过程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
ActiveDocument.Selection.GoToLine BeginLine
for row = BeginLine to EndLine
ActiveDocument.Selection.LineDown dsExtend
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
ActiveDocument.Selection.GoToLine BeginLine
for row = BeginLine to EndLine
ActiveDocument.Selection.LineDown dsExtend
next
end if
end if
end Sub
然后保存。
然后选中某段代码,然后tools-marco...,选择SetSelNote,然后Run,就把选中的注释掉了。
当然,如果你再加模板代码,一样的。
然后,你就知道怎么用了。