From: iamnu on 4 Jan 2010 06:46 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 Fields. 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, Bernie 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 ActiveDocument.FormFields(myformfield).Next.Select Else ' If the current form field is the last one, ' go to the first form field in the document. ActiveDocument.FormFields(1).Select End If Else ' 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 FindKey(KeyCode:=BuildKeyCode(wdKeyReturn)).Disable ' Disables prompt to save template changes. Templates(1).Save End Sub
|
Pages: 1 Prev: Word is open, closing and saving very slow. What to do? Next: Creating a new TOC style |