Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
JustSomeGuy JustSomeGuy is offline
external usenet poster
 
Posts: 39
Default Macro to calculate and insert number of elapsed years?

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.
  #2   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?

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.

  #3   Report Post  
Posted to microsoft.public.word.docmanagement
JustSomeGuy JustSomeGuy is offline
external usenet poster
 
Posts: 39
Default Macro to calculate and insert number of elapsed years?

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.

  #4   Report Post  
Posted to microsoft.public.word.docmanagement
JustSomeGuy JustSomeGuy is offline
external usenet poster
 
Posts: 39
Default Macro to calculate and insert number of elapsed years?

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.

  #5   Report Post  
Posted to microsoft.public.word.docmanagement
JustSomeGuy JustSomeGuy is offline
external usenet poster
 
Posts: 39
Default Macro to calculate and insert number of elapsed years?

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.



  #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.

  #7   Report Post  
Posted to microsoft.public.word.docmanagement
JustSomeGuy JustSomeGuy is offline
external usenet poster
 
Posts: 39
Default Macro to calculate and insert number of elapsed years?

This is very handy. For years I've seen people embedding hard dates into
corporate documents, which are doomed to become outdated, requiring manual
re-editing that almost never happens because everyone's too busy. This
little gem solves that problem! THANKS!!

"Lene Fredborg" wrote:

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.

  #8   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Macro to calculate and insert number of elapsed years?

If you want the calculation to be even more accurate - see
http://www.wopr.com/cgi-bin/w3t/show...?Number=249902

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


JustSomeGuy wrote:
This is very handy. For years I've seen people embedding hard dates
into corporate documents, which are doomed to become outdated,
requiring manual re-editing that almost never happens because
everyone's too busy. This little gem solves that problem! THANKS!!

"Lene Fredborg" wrote:

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.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to calculate a date in the future v&sr4JC Microsoft Word Help 12 February 6th 09 03:49 AM
Formula for number of days elapsed? Roger Tregelles Tables 6 December 28th 06 03:50 PM
How do I calculate the number of days between two dates? UNI-SOURCE User Mailmerge 1 January 31st 06 03:04 PM
Can Word calculate page number in form only if data is entered in. Jim Page Layout 1 December 20th 05 09:59 AM
how to calculate the number of days between 2 dates in msword joe17 Microsoft Word Help 1 October 28th 05 06:22 PM


All times are GMT +1. The time now is 09:58 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"