View Single Post
 
Old 06-09-2016, 05:45 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 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

OK - That helps
Try the following
Code:
Option Explicit

Sub CreateTextField()
Dim oRng As Range
Dim aFld 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 aFld = .FormFields.Add(Range:=oRng, Type:=wdFieldFormTextInput)
        aFld.TextInput.EditType Type:=wdRegularText, Default:="Detail", Format:="First capital"
        .End = aFld.Range.End
        .Collapse 0
        'why do you need this? The bookmarks shouldn't be an issue
        'Do While .Paragraphs(1).Range.Bookmarks.Count > 0
        '    .Paragraphs(1).Range.Bookmarks(1).Delete
        'Loop
        .Select
    End With
lbl_Exit:
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    Set oRng = Nothing
    Set aFld = 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