View Single Post
 
Old 06-10-2016, 08:28 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,143
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