View Single Post
  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Lene Fredborg Lene Fredborg is offline
external usenet poster
 
Posts: 1,291
Default Macro to calculate and insert number of elapsed years?

I am glad to hear it works now. I did not see your posts until you had solved
the problems.

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"JustSomeGuy" wrote:

OK, got it at last; i just wasn't being careful enough with the pesky syntax.

"JustSomeGuy" wrote:

I tried pressing Ctrl+F9 twice to generate the double brackets, then
carefully inserting the rest of the contents...this produces the result,
"2007 -1997" instead of the desired, "10". Getting closer, but not quite
there, yet!


"JustSomeGuy" wrote:

Lene, Looks cool, but I'm getting a Syntax error even when I follow your
procedure and copy/paste your formula (from the = sign to 1977). What am I
doing wrong?



"Lene Fredborg" wrote:

The following field construction should work:

{ = { DATE \@ "yyyy" } - 1997 }

The construction consists of 2 fields, one inside the other. The DATE field
returns the current year and 1997 is subtracted from that.

The field brackets must be inserted by pressing Ctrl+F9 (field brackets
cannot be typed using normal characters). Type the remaining part of the
field construction between the brackets. When finished, press F9 to update
the field (if this does not toggle field codes, press Alt+F9).

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"JustSomeGuy" wrote:

A company was founded in 1997. Is there a way to make number of years in
business, always current, in a field? i.e., embed a formula that knows
"1997" and can take today's date minus 1997 and insert the number "10" so
that desired boilerplate text says "We've been in business for XX years" and
the number of years will always be correct, year after year, whenever the
field is updated.