The information in this article applies to:
SUMMARY
This article contains four Visual Basic for Applications macros that you
can use to emulate the Microsoft Word 6.0 for Windows functionality of the
ENTER key for moving between form fields in protected documents.
MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspWhat follows are the four Visual Basic for Applications macros that you can use together to emulate the Microsoft Word 6.0 for Windows functionality of the ENTER key in new protected form field documents based on a template. For this code to work as written, the template should not be protected. The first macro moves the insertion point to the next form field. The second macro assigns the first macro to the ENTER key. The third macro removes the assigned macro to the ENTER key, restoring the default functionality of the ENTER key. First Macro: Moves the Insertion Point to the Next Form FieldThis macro moves the insertion point to the next form field. If the current form field is the last one in the document, it moves the insertion point to the first form field.This macro uses the Bookmarks collection to retrieve the name of the current form field. The name of each form field is also the name of a bookmark inserted for the form field. If you have any other bookmarks in your document, you may have to add more code here to handle potential errors. The macro also assumes that all form fields in the documents allow user input. If this is not the case in your document, you will have to add additional code in your macro. The macro checks whether the current section is protected or unprotected, and then either moves to the next form field (in a protected section) or inserts a paragraph mark (in an unprotected section). This functionality is necessary for documents that contain both sections that are protected for form input and for unprotected sections.
Second Macro: Assigns the EnterkeyMacro Macro to the ENTER KeyThis macro attaches the EnterKeyMacro macro to the ENTER key, thereby reprogramming the function of the key when it's used in protected document form fields. When you use this macro in a custom template, name it "AutoNew" (without the quotation marks). This will change the functionality of the ENTER key in all new form documents based on the template.
Third Macro: Assigns the EnterkeyMacro Macro to the ENTER KeyAdd an AutoOpen macro with the following code. This ensures that the key functionality will continue when you open a document based on the form template in the future.
NOTE: Running either macro may disable some functions, such as AutoCorrect
and AutoTex,t and may affect other features that depend on the ENTER key
for proper operation. You will need to run the forth macro to restore the
default functionality of the ENTER key or restart Microsoft Word.
Forth Macro: Removes the Command Assigned to the ENTER KeyThis macro restores the default functionality of the ENTER key. When you use this macro in a custom template, name it AutoClose.
NOTE: The CustomizationContext property sets the location where the
keyboard customization is to be saved, in this case the template attached
to the active document.
For additional information, please see the following article in the Microsoft Knowledge Base: Q173707 OFF97: How to Run Sample Code from Knowledge Base Articles REFERENCESFor more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base: Q163435 VBA: Programming Resources for Visual Basic for Applications Additional query words: vb vba vbe word8 word97
Keywords : kbinterop kbdta kbwordvba |
Last Reviewed: November 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |