Macros and Automation - Frequently Asked Questions
1. Sending "any" keys to an applicationTo program Tesco Complete Office, use the OLE Automation features in combination with macros. This is described in the on-line help. For functionality not supported by OLE Automation, you can use a general routine to send keyboard characters to Tesco Complete Office. You can do this from both inside Tesco Complete Office and outside Tesco Complete Office. The method is "SendKeys" and it's part of Windows Scripting Host that comes with Microsoft Windows (98 and later). Example: Sub SendAbilityKeys To access special characters, use the following key codes:
To use Alt, Ctrl or Shift in combination with other characters, simply precede the character with the Alt, Ctrl or Shift key code from the above table. Examples Sub SendAbilityKeys References For general info on scripting, including latest downloads, see: For more info on "Sendkeys" in particular see: 2. Write macro to delete previous/next wordSome word processors (including Tesco Complete Office Write v4) support "Delete Previous Word" when Ctrl-Backspace is pressed. Similarly "Delete Next Word" for Ctrl-Delete. This macro example shows how Tesco Complete Office can made to do the same and includes how to assign a keystroke to a macro. 1. Start Write 2. Select Tools/Macros/Macro Editor 3. Copy and Paste all the text below into the Macro editor screen. Sub DelPrevWord 4. Click the Save button 5. Use the Window menu to return to your document (any document) 6. Select Tools/Customize and the Macro Shortcuts tab 7. Click on the Macro DelPrevWord 8. Click in the "Select New Shortcut" edit box and press Ctrl-Backspace 9. Click "Assign" button 10. Repeat 7 to 9 with DelNextWord macro and Ctrl-Delete 11. Save and test 3. How to use Programmable Forms"Forms" are used in conjunction with macros so you can provide a custom user interface for your macro program. Here's how to create a simple form in Write: Stage 1 - create the new form 1. Start Write and Select Tools/Forms Editor Stage 2 - edit the form 1. Right click over the form and select Properties. Forms.CloseActive 11. Save the Form (use the Save button) and switch to the Write Window (leave the forms program running for now). Stage 3 - write a macro to call the form 1. Select Tools/Macros and create a new macro, e.g. call it
TestForms Forms.ShowForm("My Form") 3. Run the macro to display the dialog (e.g. Right-click over macro code and select "Run"). Next steps 1 - Get data from a form 1. Go back to the forms editor and select View/Active Objects (or click on the "VB" button to toggle between script and design modes) Retval.Var("EditText") = AbilityEditBox2.Text Note that "AbilityEditBox2" is the default ID for the edit box since it was the second control placed on the form - you can change this if you want to (right-click over edit box and select Properties). 4. Return to the Write macro and add an extra line so it looks like this: Forms.ShowForm("My Form") 5. Run the macro, type something into the Edit box and select Close. What's happening? The macro shows the form, the user interacts with the form and when the form is closed, a "special" variable called "EditText" is created to hold the value of the edit box. This is then referenced by the Write macro. You can make as many of these special variables as you want to pass data from a form to the main macro. Next steps 2 - Investigate the other tools and events All the other control types and events work in the same way as described as above. You can create complex and forms and put the bulk of the macro code in the actual form as well. 5. How to use macro buttons to link Database formsHow to link two Database forms together using macros and macro buttons. Typical scenario is that you're browsing in database form view and you want a button to display a record from another (usually related) table:
Sub OpenRelatedForm () Where:
An example of a very simple system of two linked tables can be downloaded here. Open the form EmailForm, browse and use the button "Get Customer". Code is in the GetCustomer macro. 6. Automating printing of envelopesProblem - You've written a letter and now want to print only the address block on an envelope in a single step. Solution - You need to create an envelope template and a macro to copy the address block. Follow these steps: 1st part - create a new template to match your envelope size:
2nd part - create a macro
Dim s, i, n, pn, addstart, addblock, envDoc, TemplateName 3rd Part - run the macro
When the macro is run next time, skip step 3. 7. How to search and replace in WriteSuppose you had a template and wanted to search and replace a "field holder" with some text of your own. For example, in your document you type *namefld* where you want a user name to appear and *addfld* where the address should appear. The following subroutine implements a search and replace in the active document: Sub FindAndReplace(find, replace) And the following subroutine calls the above sub with some real data: Sub TestReplace 8. Use Spreadsheet to create Excel xlsHow to use automation of Tesco Complete Office Spreadsheet to create Excel files without user interaction. There is no automation method to set a "Save As" file type in Ability. The simplest way around this problem is to create a template that is an xls file (ie a normal spreadsheet in Tesco Complete Office and then saved using File/Save As and setting type to Excel). The following code shows how this can be done. Sub CreateExcelFile The above code is designed to run from any application that supports the VBScript language (e.g. Tesco Complete Office Write or Database, an Internet Explorer application (HTA) or a WScript file) but it would be easy to adjust to work with other languages. 9. Start Database and open a formHow to open a database from the desktop and automatically display a form First Part: create a link on your desktop that runs the database application
Second Part: create the macro to open a form
Now you can close the database and test the link on the desktop - the result should be that the form you want is displayed 10. Run macros from HyperlinksA neat way to provide the "glue" that links documents to macro code, macros can be run using the hyperlink function. Example using Spreadsheet
NB: You don't have to put in Click here - any description will do. Now you can click the hyperlink "Click Here" to run the macro - a simple message box will appear. The hash symbol (#) above is used to denote a macro (as opposed to a normal URL). The macro in this case is an Application level macro and is available for any Spreadsheet. It's also possible to run a macro in a document. In this case, the syntax is: =HYPERLINK("documentname#macroname", "Click here") For example, a user called Phil, with a macro called "startit" in a spreadsheet called myspread stored in my documents would enter: =HYPERLINK("C:\Documents and Settings\Phil\My Documents\myspread.aws#startit", "Click here") The HYPERLINK function can be used in a similar way in Write (use Insert/Hyperlink) and Database (create a calculated field to hold the function - see 12. Creating a Database of Links for an example). 11. How to run a macro as an application starts/Autoexecute macrosAutoexecute macros, that start when a file is loaded, are not allowed in Tesco Complete Office due to security problems - such functionality provides an easy route to spread viruses. However, it is possible to create a shortcut that opens a file and runs a macro as the application loads. The general format is: ApplicationName FileName#Macroname The first starts the Tesco Complete Office application, opens the file Filename and runs the macro called Macroname that is contained within the file. The second starts an Tesco Complete Office application and runs the Application or Global level macro called Macroname. Example 1. Suppose you want to open a database called INVOICE.ADB in My Documents and run a macro called STARTINV within the database:
12. How to create a control panel (or switchboard) in DatabaseSuppose you want a form that acts as a central point to the user and allows him to choose other forms or tables or run macros. Here is a guide on creating such a form:
Note that the above are all single line macros - you can make them as simple or complex as you want. The last of the above examples exits the database application. You can now edit the form and add text (and pictures) to make it more user friendly. See also 14. Start Database and open a form for details on how to open the form automatically. 13. How to create a toolbar button to start external applicationsYou can use the macro facilities in Write, Spreadsheet, Database and Photopaint to run external programs from toolbar buttons. The following example will show how to set this up to start Spreadsheet. All you need to change is the name of the exe (the prog= line) in step 3:
|
