View Single Post
 
Old 06-08-2016, 10:08 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,438
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

What is not working?

Code:
Sub CreateTextField()
'With the exception of this minor change you code seems to work fine.
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
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
    
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote