如题,懂的入。
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 |
受教了!呵呵!