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
目前还没有任何评论.

注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。