Insert at Insertion Point

S

Sarah_Lecturer

At the moment my macro inserts a field in my form at the bottom of the
form... how do I get it to insert a field at the current insertion point
instead? I would also like the document reprotected with the relevant
password.

Dim oRng As Word.Range
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect Password:="***"
End If
Set oRng = .Range
With oRng
.Collapse wdCollapseEnd
.InsertAfter vbCr
.Move wdCharacter, 1
End With
.FormFields.Add Range:=oRng, Type:=wdFieldFormTextInput
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
End Sub

thanks for your help xx
 
J

Jay Freedman

What you're doing now is setting oRng equal to ActiveDocument.Range
(allowing for the With statement), then collapsing it to its end and
using that range as the place to insert the field. To put the field at
the insertion point, change

Set oRng = .Range

to

Set oRng = Selection.Range

You may or may not want to keep the insertion of a paragraph mark
before the field (the .InsertAfter and .Move statements).

To reinstate the password for form protection, add the optional
parameter to the .Protect statement:

.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, _
Password:="***"

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top