Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 06-10-2016, 07:18 AM
PSSMargaret PSSMargaret is offline VBA Code to Insert Legacy Text Field Windows 10 VBA Code to Insert Legacy Text Field Office 2010 64bit
Novice
VBA Code to Insert Legacy Text Field
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default


Thanks Graham. Almost there. If I have ten sets of fields in the form and run the macro, it successfully inserts a new set of field just below the current cursor position, however, it returns the cursor to the top set of fields so I have to tab through them all to get to the new set of fields just entered.
Reply With Quote
  #17  
Old 06-10-2016, 08:28 PM
gmayor's Avatar
gmayor gmayor is offline VBA Code to Insert Legacy Text Field Windows 10 VBA Code to Insert Legacy Text Field Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Name the fields added separately and select the first of them e.g.

Code:
Option Explicit

Sub CreateTextField()
Dim oRng As Range
Dim aFld As FormField, bFld As FormField
    If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
    Selection.Paragraphs(1).Range.InsertParagraphAfter
    Set oRng = Selection.Paragraphs(1).Range.Next.Paragraphs(1).Range
    With oRng
        .ParagraphFormat.SpaceBefore = 3
        .Collapse 1
        Set aFld = .FormFields.Add(Range:=oRng, Type:=wdFieldFormTextInput)
        aFld.TextInput.EditType Type:=wdRegularText, Default:="Category", Format:="First capital"
        .End = aFld.Range.End
        .Font.Bold = True
        .Collapse 0
        .Text = ":  "
        .Font.Bold = False
        .Collapse 0
        Set bFld = .FormFields.Add(Range:=oRng, Type:=wdFieldFormTextInput)
        bFld.TextInput.EditType Type:=wdRegularText, Default:="Detail", Format:="First capital"
        .End = bFld.Range.End
        .Collapse 0
        aFld.Select 'select the first of the two added fields
    End With
lbl_Exit:
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    Set oRng = Nothing
    Set aFld = Nothing
    Set bFld = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #18  
Old 06-15-2016, 04:22 AM
PSSMargaret PSSMargaret is offline VBA Code to Insert Legacy Text Field Windows 10 VBA Code to Insert Legacy Text Field Office 2010 64bit
Novice
VBA Code to Insert Legacy Text Field
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default

Perfect! Thanks so much.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code to Insert Legacy Text Field Insert text form field help sj80 Word 1 01-26-2016 10:50 PM
VBA Code to Insert Legacy Text Field Variable text field code based on occurrences on each page Cosmo Word 2 12-29-2015 11:54 AM
VBA Code to Insert Legacy Text Field Grammar check into legacy forms > Text form field. Eduardo Care Word 2 09-09-2015 03:11 PM
VBA Code to Insert Legacy Text Field legacy Form Field sunrise06 Word 9 05-02-2015 06:48 PM
Filling in legacy field causes rest of line to move to next tab stop rtrdom Word 5 12-14-2013 05:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:16 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft