Word, Form Fields, and the Enter Key



I've posted once on this subject, with no reply. I thought I'd try
again in a different format.

I'm using the code below to act like the Tab Key to go between Form
The problem is that when using the Enter Key, the Form Fields are not
Formatted, as they are with the Tab Key.

Please, someone copy this code into a blank worksheet and try it
yourself, format some Form Fields, and tell me why the code is not
formatting the Form Fields. By the way, after using the Enter Key, if
I go back to the previous Form Field by using the left arrow or mouse,
for example and then exit the Form Field with a right arrow or Tab
Key, the Field will then show the proper formatting.

Thanks for your help,

The code below was copied from here: http://support.microsoft.com/kb/211219
Sub EnterKeyMacro()
Dim myformfield
' Check whether the document is protected for forms
' and whether the protection is active.
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields And _
Selection.Sections(1).ProtectedForForms = True Then
' Retrieve the bookmark of the current selection.
' This is equivalent to the name of the form field.
myformfield = Selection.Bookmarks(1).Name
' Go to the next form field if the current form field
' is not the last one in the document.
If ActiveDocument.FormFields(myformfield).Name <> _
ActiveDocument.FormFields(ActiveDocument.FormFields.Count) _
.Name Then
' If the current form field is the last one,
' go to the first form field in the document.
End If
' If the document is not protected for forms,
' insert a tab stop character.
Selection.TypeText Chr(13)
End If
End Sub

Sub AutoNew()
' Do Not protect the template containing these macros.
CustomizationContext = ActiveDocument.AttachedTemplate
' Bind the ENTER key to the EnterKeyMacro.
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), _
KeyCategory:=wdKeyCategoryMacro, Command:="EnterKeyMacro"

' Reprotect the document with Forms protection.
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub

Sub AutoOpen()
' This macro will reassign the ENTER key when you open an existing
' Word form fields document.
CustomizationContext = ActiveDocument.AttachedTemplate
' Bind the Enter key to the EnterKeyMacro.
KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyReturn), _
KeyCategory:=wdKeyCategoryMacro, Command:="EnterKeyMacro"
End Sub

Sub AutoClose()
CustomizationContext = ActiveDocument.AttachedTemplate
' Disables prompt to save template changes.
End Sub


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question