atw: Re: Word Macro to Complete the Dates in an Invoice from the Filename ...

  • From: LEWINGTON Warren <Warren_LEWINGTON@xxxxxxxxxxxxxx>
  • To: "austechwriter@xxxxxxxxxxxxx" <austechwriter@xxxxxxxxxxxxx>
  • Date: Thu, 5 Aug 2010 10:18:54 +1000

thx Neil.

Regards
Warren Lewington
Technical Writer
Compliance and Enforcement Branch



________________________________
From: austechwriter-bounce@xxxxxxxxxxxxx 
[mailto:austechwriter-bounce@xxxxxxxxxxxxx] On Behalf Of Neil Maloney
Sent: Wednesday, 4 August 2010 8:12 PM
To: austechwriter@xxxxxxxxxxxxx
Subject: atw: Word Macro to Complete the Dates in an Invoice from the Filename 
...

Just in case this code is useful to anyone on the list ...

I have always included the date range for my invoices in the invoice filename 
as well as in the invoice body text. The date details in the filename are in 
parentheses, e.g. "(19 July - 1 August)".

While I always update the filename when copying and then changing an invoice 
document for a new billing period, I sometimes (reasonably regularly) forget to 
update the date range in the body text.

So, I have just written a little macro that reads the filename when the 
document is open, parses it for the date - based on the date being included 
between an opening and closing parenthesis - and then saves the result in the 
Subject field in Document Properties.

I have added a "{subject}" field to my invoices, where the date used to be in 
plain text. I have also added the macro to a toolbar and called it "Update 
Invoice".

After inserting the date result into the Subject field in Document Properties, 
the macro selects the entire document and updates all fields within it. Voilà, 
I have the date range filled in automatically for me ... now if I can only 
remember each time to click the Update Invoice button !!!

The code (based on VBA for Word 2003) is shown below.

In relation to the recent thread on typefaces, I thought Peter Martin was a 
font of wisdom, but I also liked Geoffrey Marnell's style ...

Neil.


Sub Update_Invoice()

FileName = Documents(1).Name
Find_the_Opening_Parenthesis:
FirstMarker = FirstMarker + 1
    Character = Mid(FileName, FirstMarker, 1)

    If Character = "(" Then
        SecondMarker = FirstMarker
        FirstMarker = FirstMarker + 1
Find_the_Closing_Parenthesis:
    SecondMarker = SecondMarker + 1
        Character = Mid(FileName, SecondMarker, 1)

        If Character = ")" Then
        Else
            GoTo Find_the_Closing_Parenthesis
        End If

    Else
        GoTo Find_the_Opening_Parenthesis
    End If

Length = SecondMarker - FirstMarker
DateRange = Mid(FileName, FirstMarker, Length)

With ActiveDocument
    .BuiltInDocumentProperties(wdPropertySubject) = DateRange
End With

    Selection.WholeStory
    Selection.Fields.Update

End Sub


Before printing, please consider the environment.

IMPORTANT NOTICE: This e-mail and any attachment to it are intended only to be 
read or used by the named addressee. It is confidential and may contain legally 
privileged information. No confidentiality or privilege is waived or lost by 
any mistaken transmission to you. The RTA is not responsible for any 
unauthorised alterations to this e-mail or attachment to it. Views expressed in 
this message are those of the individual sender, and are not necessarily the 
views of the RTA. If you receive this e-mail in error, please immediately 
delete it from your system and notify the sender. You must not disclose, copy 
or use any part of this e-mail if you are not the intended recipient.

Other related posts:

  • » atw: Re: Word Macro to Complete the Dates in an Invoice from the Filename ... - LEWINGTON Warren