View Single Post
 
Old 06-08-2016, 07:06 AM
PSSMargaret PSSMargaret is offline Windows 10 Office 2010 64bit
Novice
 
Join Date: May 2016
Posts: 28
PSSMargaret is on a distinguished road
Default

Graham,

It works great when I insert it in a blank document and run it but when I replace my current code in between the code to unlock and lock the form it's not working.

Code:
Sub CreateTextField()

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
Reply With Quote