Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 904425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:02:52+00:00 2026-05-15T16:02:52+00:00

Here’s my current Macro Public Module CopyrightCode Sub AddCopyrightHeader() Dim doc As Document Dim

  • 0

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 = "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

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:02:52+00:00Added an answer on May 15, 2026 at 4:02 pm

    I’m not sure what you’re doing, but if that is XML (as it looks like), you should be using XQuery or whatever to locate/update the lastedit node, since that’ll handle the assorted complexities of comments and nesting and so on.

    If you’re confident of what the input text will be and are certain there’s no nasties in there, you can match that specific date format quick and dirty:

    <lastedit>\w{6,9}, \w{3,9} \d\d, \d{4}</lastedit>
    

    Or, even quicker and dirtier:

    <lastedit>[^<]+<lastedit>
    

    It depends what your needs are, how confident you are of what the file contents will be, and so on.

    Oh. So I was curious and went and looked up how Visual Studio actually does it’s regex stuff, and well… whoever did the VS regex needs to be whacked round the head.

    Translate the above standard regex into VS regex, you get these:

    \<lastedit\>:i+, :i+ :d:d, :d:d:d:d\</lastedit\>
    

    and

    \<lastedit\>[^<]+</lastedit\>
    

    Maybe. It’s hard to read the documentation because Microsoft don’t appear to want to write websites that work in modern browsers.

    Of course, that assumes macros use this insane regex instead of the normal .NET regex – if it’s the latter than the top stuff will be fine and you can ignore this craziness. 🙂

    To implement, try something like this:

    Dim reLastEdit As Regex = New Regex("<lastedit>[^<]+<lastedit>")
    
    Dim matches AS MatchCollection = reLastEdit.Matches(Input)
    
    If matches.Count > 0
    Then
        ' Change Header
        Dim NewLastEdit As String = "<lastedit>" & FormatDateTime(Date.Now, vbLongDate) & "</lastedit>"
        reLastEdit.Replace(Input,NewLastEdit)
    Else
        ' Add Header
    EndIf
    

    Or similar. Info here: http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex_methods.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 476k
  • Answers 476k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Check out this post on a simple event aggregator using… May 16, 2026 at 4:51 am
  • Editorial Team
    Editorial Team added an answer Your order of operations seems wrong. I think you want… May 16, 2026 at 4:51 am
  • Editorial Team
    Editorial Team added an answer Certainly. App Engine will scale your application up as the… May 16, 2026 at 4:51 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.