|
Download
DATEREPL.ZIP (Includes
2 macros: v1.01, 7/13/01 @ 4,485 bytes; v1.03, 7/13/06 @ 12,182
bytes; compressed ZIP file = 8,005 bytes)
Compatible with versions 6,7,8,9,10,11,12,X3
WordPerfect 11
users: See important information about using macros in the first
release of WP11 (11.0.0.233) at the top of this
page.
Macro
download and installation instructions for new
users |
There are two ways a date
can appear in WordPerfect (other
than as a date-formatted table cell):
- as a dynamic code (which
is visible in Reveal Codes as [Date]), which
means the date will automatically (dynamically) change in the
future to the then-current date, and
- as a static string of text
-- usually created by typing a date such as "Thursday, July 13, 2006" into the document -- which means
the date will remain the same if you open the document in the
future to edit it or print it.
Many templates insert the current
date as a [Date] code, which changes whenever you open the document
at a later date. Users often complain that when they re-open
a document based on such a template at a later date, the date
changes to the then-current date (taken from the system clock),
and doesn't show when the document was actually saved.
Also, when you press <Ctrl+Shift+D>
on the default keyboard or check the box ("Keep the inserted
date current") at the bottom of the Insert, Date/Time dialog,
you'll get a [Date] code, not a string of (static) text.
How DATEREPL works:
If you want to replace all [Date] codes in a document with the current (system clock)
date in nomal text, so that they reflect the date the document
is being written or edited, just play DateRepl while in that
document. If there are [Date] codes in the document they will
be converted to text strings ("Friday, June 1, 2007"). Otherwise the macro will simply exit.
The DateText macro command
produces a static date, the same as if you typed it into the
document. It remains the same no matter when you open the doc
in the future.
Note that, since a macro can
also "bookmark" a static date at the same time it creates
one, the [Bookmark] codes can be found later by a macro to update
a static date. This is the idea behind version 1.03 of this
macro, included in DATEREPL. (Be sure not to remove these
bookmarks later, or the macro will fail or not run properly.)
TIP: You may want to insert/update static
dates at print time (assuming that is the only time an
updated date is truly needed, since you can see the date the
file was saved in the File Open dialog). This macro can be used
as a template macro, associated with the PRE PRINT trigger. (See
WP's online Help <F1> index for more information on associating
template macros with trigger events, or see the author's "Automating
WordPerfect Templates" on the Tips
page.)
Two macros are included:
Version 1.01 is the original
version. It simply finds all date codes and converts them to
text dates. It does not insert and save [Bookmark] codes at static
date locations into the document (as the next version does).
It simply replaces any [Date] codes with the current date as
a string of text characters.
Version 1.03 includes the ability
to convert existing date codes (same as v1.01) but if it is used
multiple times on the same document it will also update any static
dates created when the macro was last played on that particular
document (the document will contain special bookmarks
around each converted date as a result of the initial conversion;
be sure not to delete them).
Intermediate-to-advanced
user tips:
|
1. Automatically insert
the current date as a static date -- i.e., a string of text characters (i.e., a static date) in new documents
such as letterheads or memos, as soon as they are opened. You
can also position the cursor, ready for typing body text. This
requires modifying the template on which the document is based,
which is easy to do, but it does require recoding a simple template
macro to do the job. See here.
2. Automate the updating
of several static dates in a template with a template macro
Similar to the above tip, but
you would use a template macro to insert the current (static)
date in several locations. [This is the technique used
in the LETTERHD template in the Library.]
Unlike the DATEREPL macro, which
replaces existing date codes in the template with dates composed
of text strings, this technique simply finds certain pre-marked
locations in the template and inserts static dates at those locations.
Here's how.
- Open the template and edit it
to remove any [Date] codes. (Unless, of course, they are needed
by any template macro that might be in the template.)
- Then insert a text placeholder
such as [Date1] where the date should go. Just type it in the
template where needed. (If you need more dates to be updated,
use [Date1], [Date2], etc.)
- Next, select each date,
including the brackets (if any), and click Tools, Bookmark, Create,
OK. (Be sure NOT to change the name that WordPerfect uses, or
uncheck the "Selected Bookmark" checkbox when the Create
Bookmark dialog appears.)
- This will place a paired
bookmark around the text placeholder(s). You can see it in Reveal
Codes. This is what WP's Prompt Builder does.
- Next, create a template macro
with code like this (the example below assumes you have 3 dates
somewhere in the doccument)::
|
OnError(End@)
BookmarkBlock ("[Date1]")
Type (DateString (DateAndTime(); Format: "MMMM d, yyyy"))
BookmarkBlock ("[Date2]")
Type (DateString (DateAndTime(); Format: "MMMM d, yyyy"))
BookmarkBlock ("[Date3]")
Type (DateString (DateAndTime(); Format: "MMMM d, yyyy"))
Label (End@)
Quit |
The format of the date can be
changed. See WordPerfect's Macro Help, under the DateString command.
Finally, you probably should
associate the above macro with the PRE PRINT
trigger, assuming the dates in a document are important only
when the document is printed. Then, each time you go to print
the document (and as long as the template itself is still on
your system), the macro will fire up and replace whatever is
between each paired bookmark. The first time the template macro
plays it will replace the text placeholder; at subsequent times
it will replace (overwrite) the entire typed date. This is a
handy way to show a "print date" on a document.
Related tips:
- If you need help creating template
macros or associating template macros with trigger events, see
"Automating
WordPerfect Templates," on the Tips
page.
- Note that you can actually edit
a date (or whatever is between each paired bookmark) and change
it -- it's just a string of text characters -- but when the macro
plays, the dates will be replaced with the current date (assuming
the bookmarks have not been deleted!).
- One thing to be aware of in
this approach is not to delete the bookmark(s) or the macro will
not know where to put the new dates. In this macro, if you delete
one or more bookmarks the macro will simply exit (Quit) when
it can't find a bookmark. The OnError command suppresses any
message if a bookmark is not found. (When bookmarks are not found,
WP generates an Error condition, not a NoFound condition.)
3. Need to insert a date
that is "n" days after the current date? Here's a code snippet from Roy ("lemoto")
Lewis:
x=DateAndTime+n
y=DateString (x;;"dd/MM/yyyy")
... where "n" is the
number of days to add to the current date. See the DateString
command for other parameters.
|
|