VS 매크로

2008. 5. 15. 16:36
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module Module1
    Sub FindUP()
        Dim Sel As TextSelection = ActiveDocument.Selection
        If (Not Sel.IsEmpty()) Then
            DTE.Find.FindWhat = Sel.Text
        End If
        DTE.Find.MatchCase = False
        DTE.Find.MatchInHiddenText = True
        DTE.Find.MatchWholeWord = False
        DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
        DTE.Find.SearchSubfolders = False
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.Backwards = True
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.Execute()
    End Sub
    Sub FindDown()
        Dim Sel As TextSelection = ActiveDocument.Selection
        If (Not Sel.IsEmpty()) Then
            DTE.Find.FindWhat = Sel.Text
        End If
        DTE.Find.MatchCase = False
        DTE.Find.MatchInHiddenText = True
        DTE.Find.MatchWholeWord = False
        DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
        DTE.Find.SearchSubfolders = False
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.Backwards = False
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.Execute()
    End Sub
    Sub SelectionLines()
        Dim Sel As TextSelection = ActiveDocument.Selection
        Dim txt As String
        If (Sel.IsEmpty()) Then
            Sel.SelectLine()
        End If
        If (Sel.ActivePoint.AbsoluteCharOffset = Sel.BottomPoint.AbsoluteCharOffset) Then
            Sel.SwapAnchor()
        End If
        If (Sel.TopPoint.AtEndOfLine) And (Not Sel.TopPoint.AtStartOfLine) Then
            Sel.MoveToLineAndOffset(Sel.TopPoint.Line + 1, 1, True)
        End If
        If (Sel.ActivePoint.AbsoluteCharOffset = Sel.TopPoint.AbsoluteCharOffset) Then
            Sel.SwapAnchor()
        End If
        If (Sel.BottomPoint.AtEndOfLine) And (Not Sel.BottomPoint.AtStartOfLine) Then
            Try
                Sel.MoveToLineAndOffset(Sel.BottomPoint.Line + 1, 1, True)
            Catch ex As Exception
                txt = Sel.Text
                Sel.Insert(txt + vbCrLf, 0)
            End Try
        End If
        If (Sel.ActivePoint.AbsoluteCharOffset = Sel.BottomPoint.AbsoluteCharOffset) Then
            Sel.SwapAnchor()
        End If
        Sel.MoveToLineAndOffset(Sel.TopPoint.Line, 1, True)
    End Sub
    Sub SelectUp()
        Dim Sel As TextSelection = ActiveDocument.Selection
        Dim txt As String
        Dim frontLine As Integer
        Dim backLine As Integer

        SelectionLines()

        frontLine = Sel.TopPoint.Line
        backLine = Sel.BottomPoint.Line

        txt = Sel.Text
        Sel.Delete()
        Sel.LineUp()
        Sel.Insert(txt)
        Sel.MoveToLineAndOffset(frontLine - 1, 1)
        Sel.MoveToLineAndOffset(backLine - 1, 1, True)
    End Sub
    Sub SelectDown()
        Dim Sel As TextSelection = ActiveDocument.Selection
        Dim txt As String
        Dim frontLine As Integer
        Dim backLine As Integer

        SelectionLines()

        frontLine = Sel.TopPoint.Line
        backLine = Sel.BottomPoint.Line

        txt = Sel.Text
        Sel.Delete()
        Sel.LineDown()
        Sel.Insert(txt)
        Sel.MoveToLineAndOffset(frontLine + 1, 1)
        Sel.MoveToLineAndOffset(backLine + 1, 1, True)
    End Sub
    Sub DuplicateUp()
        Dim Sel As TextSelection = ActiveDocument.Selection
        Dim txt As String
        Dim frontLine As Integer
        Dim backLine As Integer

        SelectionLines()

        frontLine = Sel.TopPoint.Line
        backLine = Sel.BottomPoint.Line

        txt = Sel.Text

        Sel.MoveToLineAndOffset(frontLine, 1)
        Sel.Insert(txt)
        Sel.MoveToLineAndOffset(frontLine, 1)
        Sel.MoveToLineAndOffset(frontLine + backLine - frontLine, 1, True)
    End Sub
    Sub DuplicateDown()
        Dim Sel As TextSelection = ActiveDocument.Selection
        Dim txt As String
        Dim frontLine As Integer
        Dim backLine As Integer

        SelectionLines()

        frontLine = Sel.TopPoint.Line
        backLine = Sel.BottomPoint.Line

        txt = Sel.Text

        Sel.MoveToLineAndOffset(backLine, 1)
        Sel.Insert(txt)
        Sel.MoveToLineAndOffset(backLine, 1)
        Sel.MoveToLineAndOffset(backLine + backLine - frontLine, 1, True)
    End Sub
End Module

Posted by Genesis

카테고리

분류 전체보기 (52)
The, 내 생각 (3)
The, 다른 눈 (1)
The, 겔러리 (14)
책 구절 (9)
잡동사니 (13)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

태그목록

달력

«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

글 보관함