views:

16

answers:

1

I've got a macro that updates a copyright header with the most recent edit date.

The problem I have is that the macro currently reads through the entire file rather than just the first 6 lines (which is all it needs).

Is there a way to get the Macro to only read the first "X" lines rather than the entire file?

Private selection As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
Private Sub UpdateCopyrightHeader()

    selection.StartOfDocument()
    selection.EndOfDocument(True)

    Dim content As String = selection.Text
    Dim result = System.Text.RegularExpressions.Regex.Replace(content, regex, "<lastedit>" & FormatDateTime(Date.Now, vbLongDate) & "</lastedit>")

    selection.Delete()
    selection.Collapse()
    Dim ed As EditPoint = selection.TopPoint.CreateEditPoint()
    ed.Insert(result)

End Sub
+1  A: 

You need to call LineDown instead ofselection.EndOfDocument(True):

selection.StartOfDocument()
selection.LineDown(True, 6)
SLaks
perfect this works. As a subsequent question.. .do I have to run the StartOfDocument or does it suffice to ONLY read the 6th line?
rockinthesixstring
I don't know; try it.
SLaks