VC切换注释宏代码

如题,懂的入。

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

关于Burgess Lee

人能常清静 天地悉皆归
此条目发表在技术相关分类目录,贴了, , 标签。将固定链接加入收藏夹。