Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate

Barry MacDonnell's
Toolbox for WordPerfect

Macros, tips, and templates for Corel® WordPerfect® for Windows®
© Copyright 1996-2017 by Barry MacDonnell. All Rights Reserved.

Page updated Oct 22, 2015

DATEREPL - Change all date codes (dynamic dates) to text (static dates)

Download DATEREPL.ZIP (Includes 2 macros: v1.01.01, 2/17/11 @ 7,003 bytes; v1.03.01, 2/17/11 @ 12,901 bytes; compressed ZIP file = 9,355 bytes)

Compatible with WordPerfect 6 and later versions

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.

Downloading, Documentation, Modifications, and Support

 

There are two ways a date can appear in WordPerfect (other than as a date-formatted table cell, which is another topic):

  • A date can appear as the result of inserting a dynamic code (which is visible in Reveal Codes as [Date]). This means the date will automatically (dynamically) change to the then-current date if the document is opened in the future.
  • A date can appear as a static string of text -- usually created by typing a date such as "Thursday, July 29, 2010" into the document. This means the date will remain the same if you open the document in the future to edit or print it.

Some confusion can result from these two different ways of producing a date in a document, since they can look the same on screen and on the printed page.

For example, many templates (such as automated Projects in the File, New from Projects list) insert the current date as a [Date] code, which changes whenever you open the document at a later date. This is by design: It was thought to be a convenient way to help you create letters and similar form documents -- most of which are one-time affairs.

However, people often complain that when they re-open a document based on such a template at a later date -- perhaps to print a copy of it -- the date changes to the then-current date (taken from their computer system clock), and doesn't show when the document was originally written.

Also, if you insert a date with Insert, Date/Time and you check the box ("Keep the inserted date current") at the bottom of the dialog, you'll insert a [Date] code in the document, not a string of (static) text. If you expected the latter, you might be annoyed when the date "spontaneously" changes the next time you open the document for editing or printing. The checkbox really means "Insert a dynamic date code that always reflects the current (system) date."

The DATEREPL macro was designed to help remedy these issues.

How DATEREPL works

If you want to replace all existing [Date] codes in a document with the current date (taken from your computer's clock) with nomal text (e.g., "August 20, 2008"), so that they reflect the date the document is being written or edited (i.e., today's date), just play DateRepl while in that document. If there are [Date] codes in the document they will be converted to text strings using the current system date -- just as though you had manually deleted the [Date] codes and typed the current date in their place. If there are no [Date] codes the macro will simply exit.

The macro command DateText is used to produce the static date -- the same as if you typed the current date into the document. Thus, the date will remain the same no matter when you open the document in the future.

Note: There is a limitation to the WordPerfect program with respect to finding some codes -- such as those inside another code -- which in turn limits this macro. So if a [Date] code is inside a [Style] or [Delay] code, or inside a text variable, the macro won't see it. See Footnote 1 for an explanation and a macro workaround for editing those styles.

Two macros are included

Version 1.01

This 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 just replaces any [Date] codes with the current date as a string of text characters.

Version 1.03

Since a macro can also "bookmark" a static date at the same time it creates one, these [Bookmark] code(s) can be found later by a macro to update the static date(s), too. This is the idea behind version 1.03 of this macro. (Be sure not to remove these bookmarks later, or the macro will not run properly.)

This version of the macro 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).

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 (v1.03) 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.)

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 recording 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 short 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 text placeholder, including the brackets (if any), and click Tools, Bookmark, Create, OK.
    • [N.B.: Be sure not to change the name that WordPerfect uses, or uncheck (disable) the "Selected Bookmark" checkbox, when the Create Bookmark dialog appears. The name needs to be the same in the BookmarkBlock command in the snippet below, and the checkbox needs to be ticked (enabled) so that a paired bookmark is created, not a single bookmark. All this is easier if you just click OK after you click Create.]
  • This will place a paired bookmark around -- i.e., bracketing -- the text placeholder(s). You can see it in Reveal Codes: it will look something like [Bookmark>[Date1]<Bookmark]. [Note that this is also what WP's Prompt Builder does.]
  • Next, create a template macro (see here for more) with code like the example below -- which assumes you have 3 (bookmarked) dates somewhere in the doccument:

// Macro snippet begins

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@)

// Macro ends

Note that the format of the date used in the Type commands above can be changed. See WordPerfect's Macro Help, under the DateString command.

Or, instead of a Type() command you could just use DateText to insert the current date as a static date.

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 and notes:

  • 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) in the template or the document, or the macro will not know where to put the new dates. In the above macro, if you delete one or more bookmarks the macro will simply exit (Quit) when it can't find a bookmark. [The OnError command effectively suppresses any error message if a bookmark is not found, by skipping down to the Label. (When bookmarks are not found, WordPerfect generates an Error condition, not a NotFound condition.)]
  • For a similar macro that can display and/or automatically insert the currently opened file's modification date and time, see this post on WordPerfect Universe. It uses the same technique (paired bookmarks) but with this bit of code added (each command is on one line):

// Store the document's path and name:
vFN:=?Path+?Name

// Extract the Modification Date and Time:
vModDate:=GetFileDateAndTime (Filename:vFN; DateType:ModificationDateTime!)

vModTime:=TimeString(vModDate;Format:"HH:mm:ss tt" )

vModDate:=DateString(vModDate;Type:Custom!;Format:"MM/dd/yyyy")

Messagebox(;"Modification Date and Time:";vModDate +NToC(0F90Ah)+vModTime)

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.

4. Create a new "current year only" date format (e.g., 2013 -- or whatever year it is):

1. Place the cursor where you want the current year to appear in the document or merge form.

2. Create a new date format with Insert, Date/Time, New Format (button); the Custom Date/Time Format dialog appears.

3. In the "Edit date/time format" field, delete all example codes. You can then insert just the [Year(4)#] code (found on the "Year" tab's list); then click OK to return to the Date/Time dialog. The new format should appear there.

4. Select (left click on) the new date format in the Date/Time dialog; be sure to enable (tick) the checkbox "Keep the inserted date current"; then click Insert.

In the document or merge form you should see (in Reveal Codes): [Date Fmt][Date]. These take the current date from the computer's system date.

Note that all date formats are saved with the program, so you should have access to the new format in any new document.

5. Use a template macro to automatically locate pre-existing bookmarks and type legal-style dates (e.g., "the 15th day of July, 2009") at those locations in new documents spawned by that template. See this post at WordPerfect Universe.

Page Top



Footnote 1

As noted above, there is a limitation to the WordPerfect program with respect to finding some codes -- such as those inside another code like the initial [Open Style] code -- which in turn limits the DATEREPL macro.

From How to efficiently use "Find:" in the Find and Replace (F&R) dialog:

"You cannot use Find and Replace to find codes inside a [Style] code (such as the initial [Open Style] code in a document or template) or inside text variables (a form of style). You also cannot use Find and Replace to find codes inside a [Delay] code. These are limitations of the program, at least for recent versions of it. You will have to edit the [Style] or [Delay] code by double-clicking on the code in Reveal Codes to edit it." [Ed.- Or, use a macro to edit the [Style] code as in the example below. Note that the macro method cannot be used to edit a [Delay] code.]

Example: Here is a demonstration macro that edits the current document's initial [Open Style] code to add a [Footer A] inside it that, in turn, contains the filename and a static (text) date in Arial 10-point font. It can be modified to delete all current codes (and any text) first, before creating new ones. Deleting everything inside a [Style] code, then creating what you need in that code, is one way to "edit" the code to your requirements.

The macro can be assigned to a menu, toolbar, or keystroke combination; see here. It could also be used as a template macro and triggered to play whenever you open a document based on that template; see "Automating WordPerfect Templates".

Note that once the macro does its job, the footer code will be inside the [Open Style] code, and if you wish to remove it you can do so by double-clicking on the [Open Style] code and deleting the new [Footer] code. (Merely using Ctrl+z will not Undo such an "internal" customization.)

// PURPOSE:
// Edits the current document's [Open Style: DocumentStyle] code to add a custom footer inside that code.

// Exit from any header, footer, note, text box, image, etc.
pExitSubstructures ()

StyleEditBegin (Style: DocStyle!; Library: CurrentDoc!)
StyleCodes (State: WithoutOffCodes!; Library: CurrentDoc!)

// Go to the end of any codes or characters in the Contents field of the Styles Editor
// (optional: you could as easily SelectAll and SelectDelete all the contents instead of merely positioning the cursor):
If(?RightCode>0 or ?RightChar<>"")
PosLineVeryEnd // (put the cursor at the end of all codes and text)
Endif

// Create a footer with the document path/name and date (as text)::
FooterA (Create!) // <= creates Footer A - change to FooterB if required
Font ("Arial")
FontSize (10p)
InsertFilenameWithPath // <= displays and prints once the file has been saved
FlushRight
DateText // <= inserts current date as a text string

// Exit from the footer and return to Styles Editor; then return to the main document:
pExitSubstructures ()
// Save changes
StyleEditEnd (State: Save!)

Quit

Procedure pExitSubstructures ()
While (?Substructure)
vSubDoc:=?CurrentSubDoc
SubstructureExit
If ((vSubDoc=10) or (vSubDoc=11))
BoxEnd (Save!)
EndIf
EndWhile
vImageType:=?BoxContentType
If(vImageType=3) BoxEnd (Save!) Endif
EndProc

Page Top