Sub hdr() Dim line As String Dim ProcType As String Dim pType As String Dim Visibility As String Dim ReturnVal As String Dim params(0, 4) As String Dim paramline() As String Dim nextspace As Integer Dim proctypepos As Integer Dim procname As String Dim x As Integer ' get the preceding declaration DTE.ActiveDocument.Selection.lineUp(1) DTE.ActiveDocument.Selection.selectline() line = DTE.ActiveDocument.Selection.text DTE.ActiveDocument.Selection.Collapse() DTE.ActiveDocument.Selection.startofline() ' DTE.ActiveDocument.Selection.lineDown(1) proctypepos = line.IndexOf("Sub") If proctypepos > -1 Then ' we have a subroutine ProcType = "' Procedure: " pType = "P" ReturnVal = "Void" Else proctypepos = line.IndexOf("Function") If proctypepos > -1 Then ' we have a function ProcType = "' Function: " pType = "F" ' find the return type Dim sep() As Char = {" ", ",", "(", ")"} Dim words() As String = line.Split(sep) If words(words.GetUpperBound(0) - 1) = "As" Then ReturnVal = words(words.GetUpperBound(0)) Else ReturnVal = "Boolean" End If Else ' we have an unknown ProcType = "' Unknown!: " pType = "X" ReturnVal = "??" proctypepos = -1 End If End If If proctypepos > -1 Then ' get the procedure name nextspace = line.IndexOf(" ", proctypepos) If nextspace > -1 Then Dim shortline As String = line.Substring(nextspace + 1).Trim() nextspace = shortline.IndexOf("(") If nextspace > -1 Then procname = shortline.Substring(0, nextspace) Else procname = shortline End If Else procname = "??" End If Else procname = "" End If ' Visibility If line.IndexOf("Public") > -1 Then Visibility = "Public" ElseIf line.IndexOf("Protected Friend") > -1 Then Visibility = "Protected Friend" ElseIf line.IndexOf("Protected") > -1 Then Visibility = "Protected" ElseIf line.IndexOf("Private") > -1 Then Visibility = "Private" ElseIf line.IndexOf("Friend") > -1 Then Visibility = "Friend" Else Visibility = "??" End If ' Parameters If line.IndexOf("()") > -1 Then ' there are no parameters ReDim paramline(0) paramline(0) = "None" Else Dim startparam As Integer Dim endparam As Integer Dim paramstring As String startparam = line.IndexOf("(") endparam = line.IndexOf(")") paramstring = line.Substring(startparam + 1, endparam - (startparam + 1)) paramline = paramstring.Split(",") End If ' Write the comment block DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "'********************************************" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = ControlChars.Tab & ProcType & procname DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Author: Andrew Fell-Gordon" DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Created: " & CStr(Now()) DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Function: " DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Visibility: " & Visibility DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Parameters:" For x = 0 To paramline.GetUpperBound(0) DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "'" & ControlChars.Tab & paramline(x) Next DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "' Return Value: " & ReturnVal DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = ControlChars.Tab & "'*********************************************" DTE.ActiveDocument.Selection.NewLine() End SubI am sure this can be done better as I wrote this early in my vb.net days (six months ago!). If anyone can suggest improvements I'd be glad to know.