Here's my current Macro
Public Module CopyrightCode
Sub AddCopyrightHeader()
Dim doc As Document
Dim docName As String
Dim companyName As String = "Urban Now"
Dim authorName As String = "Chase Florell"
Dim authorEmail As String = "[email protected]"
Dim copyrightText As String = "' All code is Copyright © " & vbCrLf & _
"' - Urban Now (http://urbannow.com)" & vbCrLf & _
"' - Infinitas Advantage (http://infinitas.ws)" & vbCrLf & _
"' All Rights Reserved"
' Get the name of this object from the file name
doc = DTE.ActiveDocument
' Get the name of the current document
docName = doc.Name
' Set selection to top of document
DTE.ActiveDocument.Selection.StartOfDocument()
DTE.ActiveDocument.Selection.NewLine()
Dim sb As New StringBuilder
sb.Append("' --------------------------------")
sb.Append(vbCrLf)
sb.Append("' <copyright file='" & docName & "' company='" & companyName & "'>")
sb.Append(vbCrLf)
sb.Append(copyrightText)
sb.Append(vbCrLf)
sb.Append("' </copyright>")
sb.Append(vbCrLf)
sb.Append("' <author>" & authorName & "</author>")
sb.Append(vbCrLf)
sb.Append("' <email>" & authorEmail & "</email>")
sb.Append(vbCrLf)
sb.Append("' <lastedit>" & FormatDateTime(Date.Now, vbLongDate) & "</lastedit>")
sb.Append(vbCrLf)
sb.Append("' ---------------------------------")
' Write first line
DTE.ActiveDocument.Selection.LineUp()
DTE.ActiveDocument.Selection.Text = sb.ToString
End Sub
End Module
What I need to do is first do a file search for the line ' <lastedit>Monday, July 05, 2010</lastedit>
(obviously as a REGEX because the date will always be different)
and if it exists, replace the date with today's date, and if it doesn't run the full insert.
Then what I want to hook up is every time I close a file, the Macro runs to update the edit date.