views:

35

answers:

1

I've got a Macro that I run that writes a copyright header to my document. Currently when the header is written, the cursor is left at the end of the header.

What I'd like to be able to do is capture the current location, write the header, and then return the cursor to the original location.

Does anyone know how this can be accomplished?

A: 

I think I've got it.

        Dim selection As TextSelection = DTE.ActiveDocument.Selection
        ''# store the original selection and cursor position
        Dim topPoint As TextPoint = selection.TopPoint
        Dim bottomPoint As TextPoint = selection.BottomPoint
        Dim lTopLine As Long = topPoint.Line
        Dim lTopColumn As Long = topPoint.LineCharOffset
        Dim lBottomLine As Long = bottomPoint.Line
        Dim lBottomColumn As Long = bottomPoint.LineCharOffset()
        Dim verticalOffset As Integer = 0

        ''# do a bunch of stuff that adds text to the page

        ''# Restore cursor to previous position
        selection.MoveToLineAndOffset(lBottomLine + verticalOffset, lBottomColumn)
        selection.MoveToLineAndOffset(lTopLine + verticalOffset, lTopColumn, True)

This is all nested within a Macro I wrote to automatically add a copyright header to each code file.

rockinthesixstring