View Single Post
 
Old 06-08-2016, 05:44 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

It is easy enough to include the default text, but I personally would do things slight differently embracing ranges.
Code:
Option Explicit

Sub CreateTextField()
Dim oRng As Range
Dim aFld As FormField
    Set oRng = Selection.Range
    With oRng
        .End = .Paragraphs(1).Range.End + 1
        .Collapse 0
        .Text = vbCr
        .Collapse 0
        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:
    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