![]() |
|
|
|
#1
|
||||
|
||||
|
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 |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Insert text form field help
|
sj80 | Word | 1 | 01-26-2016 10:50 PM |
Variable text field code based on occurrences on each page
|
Cosmo | Word | 2 | 12-29-2015 11:54 AM |
Grammar check into legacy forms > Text form field.
|
Eduardo Care | Word | 2 | 09-09-2015 03:11 PM |
legacy Form Field
|
sunrise06 | Word | 9 | 05-02-2015 06:48 PM |
| Filling in legacy field causes rest of line to move to next tab stop | rtrdom | Word | 5 | 12-14-2013 05:48 PM |