VC切换注释宏代码

2011年2月18日 | 分类: 技术相关 | 标签: , ,

如题,懂的入。

Sub ToggleComment ()
'DESCRIPTION: Toggle Comments a selected block of text.
	Dim win
	Set win = ActiveWindow
	If win.type <> "Text" Then
		MsgBox "This macro can only be run when a text editor window is active."
	Else
		StartLine = ActiveDocument.Selection.TopLine
		EndLine = ActiveDocument.Selection.BottomLine
		If EndLine < StartLine Then
			Temp = StartLine
			StartLine = EndLine
			EndLine = Temp
		End If
 
		For i = StartLine To EndLine
			ActiveDocument.Selection.GoToLine i
			ActiveDocument.Selection.SelectLine
 
			LineBlock = Trim(ActiveDocument.Selection)
			If LineBlock <> "" Then
				If Left(LineBlock, 2) = "//" Then
					LineBlock = mid(LineBlock, 3)
				Else
					LineBlock = "//" + LineBlock
				End If
				ActiveDocument.Selection = LineBlock
			End If
		Next
		ActiveDocument.Selection.GoToLine EndLine
	End If
End Sub
本文的评论功能被关闭了.