709-218-7927

The Landfall Garden House

60 Canon Bayley Road

Bonavista, Newfoundland

CANADA A0C 1B0

CPRGreaves@gmail.com

Home

Christopher Greaves

Utility Libraries

From within Word, choose Tools, Options, File Locations and note the name of your Startup folder. For historical reasons, mine reads thus:

D:\Greaves\Training\Wordprocessing\Word97\Startup

We are going to create a utility library template in that folder, and we’ll add useful procedures to the library as we go along.

Choose File, New, Template. Save your template with a name such as LibProc.dot (as in “Library of Procedures”) in your Startup Folder.

Open VBE, insert a User Module, choose View Properties to change the name of the User Module to LP1, then click on the TemplateProject item in the Project Explorer window and change the template project name to be Libproc.

In the User Module, key in a simple string Function; test it and drag the commented TEST routine inside the procedure body.

Public Function strWeekAgo() As String
strWeekAgo = Format(Now() - 7, "YYYY/MM/DD")
'Sub TESTstrWeekAgo()
'    MsgBox strWeekAgo
'End Sub
End Function

The Public Function procedure “strWeekAgo” is stored within a module within a template in your Startup folder.

Within a module of your Normal.dot type a simple test subroutine:

Sub test()
MsgBox strweekago
End Sub

It won’t compile ("Syntax Error").

Within VBE and with your Normal template active, choose Tools, References, Browse and navigate to your Startup folder. Choose FilesOfType “Word Documents” and select your Libproc.dot template. Make sure that its checkbox is turned on. Confirm and exit.

Now re-run your test subroutine. You should see the pop-up box with last week’s date within.

Since both your Template Project (Libproc) and your User Module (LP1) have meaningful names, you can have VBE assist you in generating code:

Within the code body, on a new code line, type MsgBox, a space, and then Lp1 and a period. VBE will prompt you to select your strWeekAgo function.

Within the code body, on a new code line, type MsgBox, a space, and then Libproc and a period. VBE will prompt you to select your strWeekAgo function or your LP1 module. If you elect to go with LP1, type yet another period and then choose your procedure "strWeekAgo".

At this stage in your development you probably have several useful procedures that you’d like to house within your Procedure Library.

Go ahead and migrate those procedures from your Normal.dot to your Library template.

You might want to download the current release of Utils.dot (Free from my web site), and include that in the references from Normal.dot.

If you have Utils.dot, try writing a small TEST subroutine that makes calls to my Utils procedures such as strAlphaDigitsOnly, strAlphaOnly and strAppInfo. Note that VBE will prompt you for a string parameter when you type the opening parenthesis after the names “strAlphaDigitsOnly” and "strAlphaOnly".

Sub test()
MsgBox strWeekAgo
MsgBox LP1.strWeekAgo
MsgBox libproc.LP1.strWeekAgo
MsgBox strAlphaDigitsOnly("M9C 1C9")
MsgBox strAlphaOnly("M9C 1C9")
MsgBox strAppInfo
End Sub

709-218-7927 CPRGreaves@gmail.com

Bonavista, Sunday, December 08, 2024 9:31 AM

Copyright © 1990-2024 Chris Greaves. All Rights Reserved.