|
Although the Dragon NaturallySpeaking scripting language for command and control macros is quite powerful, it is not as powerful or pass efficient as using the built-in scripting language inside of Microsoft Word (VBA) when controlling Microsoft Word itself. On this page, I will present two different techniques which can be used to call macros inside of Microsoft Word from Dragon NaturallySpeaking. This topic assumes that you are at least somewhat familiar with the VBA macro language of Microsoft Word 97. Method Number One -- DDE It is possible to communicate between Dragon NaturallySpeaking and Microsoft Word 97 using DDE. DDE is the name of an old Windows communication protocol. Actually, Microsoft does not recommend using DDE to talk to Microsoft Word 97 because DDE is not as reliable as other means. But DDE calls are supported by Dragon NaturallySpeaking, and it is possible to make them work. Here is an example of how to call a macro inside of Microsoft Word from a macro created inside of Dragon NaturallySpeaking. First, here is the Dragon NaturallySpeaking macro. Command name: Test Macro Application name: WINWORD (Microsoft Word 97) Window name: Microsoft Word Script:
Now here is the Microsoft Word macro. This should be included in the normal.dot template. Sub TestMacro__( param As String )
The key to making this work is to make sure that your macro name inside of Microsoft Word ends in two underscores. For some reason, Microsoft Word adds two underscores to any name of any macro passed to it using DDE. Note that the MsgBox command is included for illustration purposes only. You do not need a MsgBox command to make this work. In the example above, I have passed a single string parameter. You can of course form this string parameter inside of Dragon NaturallySpeaking from, for example, words from lists in the macro name itself. Using DDE is actually quite efficient. The only problem with DDE, is that every once a while you will get a time-out which manifests itself as an error message displayed by Dragon NaturallySpeaking when you execute your macro. You can safely ignore this message, but it is annoying. During my demonstrations, it usually only happens on the first command I give which use DDE. Method Humber Two -- Using an InputBox This alternate way of communicating between Dragon NaturallySpeaking and Microsoft Word 97 is a little less fancy than using DDE, but it is somewhat more reliable. The trick will be to create a macro which is bound to a keystroke sequence in Microsoft Word. Then when Dragon NaturallySpeaking sends those keys to Microsoft Word, the macro will be executed. This technique would not be very powerful if you had to create a different macro and a different key sequence for every time you want to communicate between Dragon NaturallySpeaking and Microsoft Word. However, using the InputBox function of Microsoft Word, it is possible to pass a string parameter from Dragon NaturallySpeaking to Microsoft Word. This gives you the flexibility inside of Microsoft Word of implementing a number of different operations based on the passed parameter. Here is the Dragon NaturallySpeaking scripting command which sends a parameter to Microsoft Word. Command name: Test Macro 2 Application name: WINWORD (Microsoft Word 97) Window name: Microsoft Word Script:
And here is the Microsoft Word macro. The name of this macro is not important, but you must attach this macro to a Microsoft Word shortcut key. (You can do this from the Tools menu, Options dialog. Click the Keyboard button, select the category of "Macros", and your macro from the list box. Then enter your new shortcut the which is Alt+Ctrl+Shift+f, and click Assign.) Sub TestMacro()
The way the second technique works is to instruct Microsoft Word to display a dialog box off of the screen, then Dragon NaturallySpeaking types the string parameter into this dialog box and hits enter. The dialog box returns the value typed into it to the macro which can then be used in subsequent processing. In order for the second technique to work properly, not only do you have to assign your macro to the shortcut key Alt+Ctrl+Shift+f, but you also must set the Key Delay to 0 or your macro will work very slowly. (Refer to the topic How to Speed Up Macros and NaturalText for details about the Key Delay.) Conclusion In summary, I have presented to techniques for communicating between Dragon NaturallySpeaking and Microsoft Word. Both techniques have their advantages and disadvantages. Someone who is familiar with writing macros in Dragon NaturallySpeaking, and somewhat familiar in writing macros and Microsoft Word, can create some very fancy macros using a combination of code in both programs.
|
|