【发布时间】:2010-07-05 19:13:39
【问题描述】:
这是我当前的宏
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 = "chase@infinitas.ws"
Dim copyrightText As String = "' All code is Copyright © " & vbCrLf & _
"' - Urban Now (http://mysite.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
我需要做的是首先对' <lastedit>Monday, July 05, 2010</lastedit> 行进行文件搜索(显然是作为正则表达式,因为日期总是不同的)
如果存在,将日期替换为今天的日期,如果它没有运行完整的插入。
然后我想挂钩的是每次关闭文件时,宏都会运行以更新编辑日期。
【问题讨论】:
标签: regex visual-studio macros