Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate |
![]() Toolbox for WordPerfect |
||
Macros, tips, and
templates for Corel® WordPerfect® for Windows® |
Page updated May 17, 2016 |
|
WordPerfect
Tips Main tips page | Browse more tips |
|
Automatically insert the current date as unchanging text in a letterhead or other template Note: If you are editing an existing document that has
lots of date codes that cause those dates to change each time
you open the document, and want to replace all of them with the current
date (as text strings, not codes), see the DATEREPL ("date replace") macro in the Library. It
was designed to be played from a toolbar button or keystroke
combination ("shortcut") whenever you need to replace changeable dates with static
dates in an existing document. (Some tips there explain how to update static dates, too.) |
Background Typically there are two ways a date can appear in
WordPerfect (another way is 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 "Friday, October 23, 2015" 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. Moreover they can both be used in the same document. In light of this, how can you automatically insert a date that remains constant
so it always displays (and prints) the same on any future day, instead
of being updated to the current date when you load the document? There are several ways to do it, and the methods depend partly on your preference and partly on the complexity of the document. Methods for documents that usually need just one unchanging date (such as at the top of a letterhead) Use a mouse click (manual method) At the very bottom of the WordPerfect window is the Application Bar (a.k.a. "status bar"). (This feature is in WordPerfect 9 and later versions.) Tip The Application Bar has clickable "document tabs" [screen shot] of a sort to let you use a mouse to quickly move between open documents. [You can also use your keyboard to shift back and forth between open documents: see this PDF file that contains a table of keyboard shortcuts.] - In case you don't see any
of these tabs: With a WordPerfect menu active (right-click on the menu
bar and choose <WordPerfect Menu>) then (in WordPerfect 9 and
later) click on View, Application Bar to display it. (If you use a
Microsoft Word menu, you can then re-enable it the same way.) - In case you don't see some
of these tabs: In WPX6+ if you have enabled Tools, Settings, Files,
"Outside WordPerfect, open documents in new application window," then
open an existing file in Windows Explorer (or other file manager), you
will not see the other tabs because they are in separate instances
(separate windows) of WordPerfect. The Application Bar can be right-clicked to
choose Settings, which allows adding various items to it -- including a
small button to insert the current date. Once the date button is available and clicked it will insert the date at the cursor location as a static (unchanging) text string
-- not a [Date] code (via Insert, Date/Time) that changes according to
the current date (which is taken from the computer system's date). It does the same thing as typing the date into the document. Note that the format of this inserted date
will be the same as the format currently chosen in Insert, Date/Time.
[This dialog is also used to insert the date as a changeable code (visible in Reveal Codes) by checking (ticking) the box, "Keep inserted date current".] Use a recorded macro (automatic method) This requires a little different procedure
from what would be required to insert the current date via a date code.
(That is, typically by using Insert, Date/Time, <choose a date
format> and then enabling (ticking) the checkbox "Keep the inserted
date current". This places at least one format code at the cursor
location, visible in Reveal Codes. The code will always display the current date using the computer system's internal date; hence, it is changeable, not fixed.) Instead, you will use a simple recorded macro to have WordPerfect automatically insert the current date as a static text string and not a date code whenever you load a new document based on a template that contains the macro, such as a letterhead, invoice, etc. (If you want to change all date codes in an existing document to text strings, see the sidebar note in the left column.) Thus, it places an unchanging date in the document as soon as you open it -- the same as if you had typed the date. Since the current date will be inserted as
text
characters this is
done just once by the macro when you load a new document from the
template (usually with File, New from Project or File, New in WP8 and
earlier). If you reopen the document at a later date you will need to
manually change the date in it. (There are macro methods to locate multiple static date areas in a document and update them. See the note in the left sidebar above.) It is simple and straightforward technique,
and should be relatively easy for even a novice user in simple templates such as used for correspondence or invoicing. (See
the method below, which replaces multiple date codes in more complex documents.) Here's how to do it: [1] Open your letter or other template (i.e.,
either edit it or create a new one using the Options button in the
File, New from Project dialog window).
[2] The first -- and very easy -- step is to record a template macro. Click on Tools, Template Macro, Record. A dialog will pop up at this point. Enter a name for your new macro (e.g., "Insert date as text") in the top field, and click the Record button. (Note that a Macro Toolbar is now displayed on screen. You'll use this later to stop the macro recording.) At this point, your keystrokes and menu selections are now being recorded. [3] Place the cursor where the date should go, if it is not already there. Tip: You can hit the <Enter> key, <Spacebar>, etc.,
or use the Format, Typesetting, Advance feature to specify an exact
location. (Remember, your actions are being recorded, so it might be a
good idea to list these extra customization steps and settings in
advance so that you'll produce a "cleaner" template macro.)
[4] Using the main WordPerfect menu, click Insert, Date/Time. Select the date format you need -- but be sure that "Keep inserted date current" is NOT checked -- then click Insert. The date (as text) should now be displayed on screen at the cursor location. Repeat to insert other dates, such as inside a header or a footer. Tip: At this point you might want to use the <Enter> key
to move down a few lines below the date to where the recipient's
address will eventually be typed.
[5] Click the leftmost button -- the one with a small black square on it -- on the Macro Toolbar to stop the macro recording. Now, before you save your work you need to do several things. [a] You need to remove the new
text date, hard returns [HRt], and any [Adv] codes you just entered
from the main document screen (use the Reveal Codes window to help locate them;
or use Edit, Undo to remove these items from the template).
Reason:
You want to save your newly edited template without this new
stuff, and have the macro do the work of inserting the text date, hard
returns, etc., later, whenever you open a new document based on this
template. If you don't remove the items you just entered in the
template, you'll get two dates, etc., in new documents. So, remove just
those things from the letter template document that were entered during
the macro recording process above. (Note that this does not remove the
macro you just recorded, only the results of your actions during the
creation of the macro. The macro code will be saved in the template
file itself, which is what you want to do.)
[b] You need to "associate" this template macro with something called the "Post New trigger" so that it will play as soon as you open a new document (hence: Post New) based on the template. Here's how:
While the template is being edited,
click the Associate button on the template toolbar. In the dialog that
pops up, click the Triggers radio button. Then select (click) "Post
New" in the left pane, and choose the new template macro's name from
the Macros drop list. Click OK to close the Associate dialog.
Important: If you see something called "<dofiller>" already associated with the Post New trigger, stop now and read Footnote 1. Otherwise, continue. [c] If this was a pre-existing template,
it might have been set up with one or more dates inserted as codes so
that they always display (and print) the current date.
You probably will want to remove these [Date] codes unless you really want them to always show the current date when you open the document in the future. Open Reveal Codes and examine the template; remove any unwanted [Date] codes with the <Delete> key or by dragging the codes from the Reveal Codes window. (Be sure to check for such codes in any header or footer by simply clicking your mouse inside these structures.) [6] Finally, save your modified template with
File, Save, and exit from the template with File, Close, or click
the rightmost button on the template bar.
[7] Test your changes. Open a new document based on this template; the date (as text, not as a [Date] code) should be automatically entered. If you added hard returns or an Advance code, the cursor should move down a few lines, waiting for the recipient's name and address to be typed. A method for documents containing one or more changeable [Date] codes that can change the codes to static text characters The advantage this method has over the
method above is that it might make the template creation/modification process
easier for you, especially in a complex template. It uses an existing
macro (DATEREPL, here in the Library) that will automatically change any existing date codes to text
dates when you open a new document based on that template. [Tip: That macro download page also has some tips to automatically locate certain identical text dates in a document and update all of them. This can be faster and more convenient that using Find and Replace to change some dates.]
This method saves you the minor effort of recording a new template macro, removing changes to the template, etc., as described in the method above. It also makes it slightly easier to insert current fixed dates where you need them, since you do this in advance by inserting date codes in those locations in the template itself and then let the macro convert them to character strings when documents based on the template are opened. A disadvantage is that it doesn't easily let you add extra elements (hard returns, etc.) as you might do with your own custom macro. [1]
Create the new template (or edit the old
one) and use [Date] codes wherever you need them. (This is the way many
WordPerfect Projects work when they need to display a date.) That is,
when you
insert dates in the body text, headers, etc., with Insert, Date/Time,
be sure to check (tick) the box "Keep the inserted date current," which
inserts the date as a [Date] code rather than as a string of typed
characters.
(Tip: To
save typing time in creating the new template, you could insert an
entire existing document into the new template with File, Insert. See Custom templates here.)
[2] Then use the DATEREPL macro as a template macro, associated with the Post New trigger. This way, you can have [Date] codes in body text, headers, footers, etc., and the macro will find all of them all and replace them with today's date as a string of typed characters.
Here's
how:
[a] First be sure DATEREPL.WCM is in your default macro directory. (For help see here.) Then copy DATEREPL.WCM into the new template:
From
the template toolbar click Copy/Remove Object. In the next window,
under "Object type:" select "Macros on disk." Click the button on the
"Source:" field to select the DATEREPL.WCM macro from the directory. Then click the
Copy>> button, then click Close. The macro is now embedded in the
template as a template macro.
[b] Next, click Associate from the template property bar, then click the "Triggers" radio button. [c] In the "Item to Associate" list, select "Post New." (By associating the macro with the Post new trigger, the macro will automatically play immediately whenever a new document is opened based on that template.) Important: If you see something called "<dofiller>" already associated with the Post New trigger, stop now and read Footnote 1. Otherwise, continue.
[d] In the "Macros" drop list, select the
macro (Daterepl), then click OK.
[e] Save the template. If it is a new template, give the template a description and a filename in the Save Template dialog (see the Help button for more information), and select a Category for the new template (such as Custom WP Templates). Note that the only part of DATEREPL that is important for the operation of this template macro is shown below. You could comment out (or delete) all other lines in that macro before copying it into the template: PosDocVeryTop MatchSelection OnNotFound (END@) While(1) // Enter [Date] in the SearchString command with // the Codes button on the macro toolbar: SearchString ("[Date]") SearchNext (Extended!) DateText EndWhile Label(END@) Tip For a more complete treatment on letterheads and other automated documents, see LETTERHD in the Library, which contains sample templates. [Page top] |
The <dofiller> is the oddly named built-in function (a macro, really) that pops up the Template Information dialog when you open a document based on a template that uses this function (not all templates use it). If you see a dialog with fill-in fields (also called "prompts") when you open such a document, it's because the template uses <dofiller> to display the dialog and insert the material in each field in various locations in the document. Unfortunately, only one macro can be associated with any given template trigger. You should not blindly replace <dofiller> with your own macro or any other macro, or you most likely will change the function of the template in a way you do not expect or do not want. You can work around this problem, but you
should learn about the triggering function and how to code a macro to
incorporate both the function of <dofiller> and the
function of date-code replacement, such as described on this page and
coded in the DATEREPL macro. Typically, this simply means adding a single command (TemplateFill) to the beginning of the macro that does some custom work -- such as the replacement of date codes -- and then associating that macro with the Post New trigger. This comes under the topic of "Automating WordPerfect Templates," which is comprehensively described here. [Although the linked document (a PDF file) is a bit lengthy, it can pay great dividends in productivity -- not to mention reduced frustration -- in the future, especially if you are tasked with automating WordPerfect.] [Page top] |