在Visual Studio中运行宏直到文件末尾

时间:2012-03-21 21:31:12

标签: c# visual-studio visual-studio-2008 macros

Visual Studio 2008是否有一些AddIn或扩展,允许我运行Macro直到文件结尾?我真的很讨厌按住CTRL + SHIFT + P并等到文件结束。

1 个答案:

答案 0 :(得分:5)

您可以录制宏,然后打开宏IDE(Alt + F11)并将预先录制的宏放在这样的循环中:

Sub TemporaryMacro()
    selection = DTE.ActiveDocument.Selection()
    anchorPoint = selection.AnchorPoint.CreateEditPoint
    selection.EndOfDocument(True)
    endPoint = selection.BottomPoint.CreateEditPoint()
    selection.MoveToPoint(anchorPoint)

    Do While True
        isEOF = DTE.ActiveDocument.Selection.TopPoint.CreateEditPoint().Line = endPoint.Line
        If (isEOF) Then
            Exit Do
        End If

        ' Prerecorded macro
        DTE.ActiveDocument.Selection.Text = " "
        DTE.ActiveDocument.Selection.LineDown()
        DTE.ActiveDocument.Selection.CharLeft()
        ' End of prerecorder macro

    Loop
End Sub