Sub MAIN
StartOfDocument
' Turn screen updating off.
ScreenUpdating 0
' Note that "<TEXTFIELD>" (below) needs to be
whatever the user has
' as a temporary text form field "replacement" in
their original
' merge document.
EditFind .Find = "<TEXTFIELD>", .Direction =
0, .Wrap = 1
' This makes sure that there are actually
more "fields" to replace
' before putting in a new form field. Without this
it would endlessly
' insert text form fields at the end of the document.
While EditFindFound()
InsertFormField .Enable = 1, .TextType =
0, .TextWidth = "0"
EditFind
Wend
ScreenUpdating 1 'Turn screen updating back on.
StartOfDocument
End Sub
I did the same thing with another macro that divides the
merged document into separate documents and that worked
fine.
That code is for versions of Word before Word97 with which WordBasic was
replaced by VBA. If you are entering the data into the formfields before
executing the merge, the following code will unlink the text that is entered
into the formfields so that it will be like ordinary text in the document:
Dim ff As FormField
ActiveDocument.Unprotect
For Each ff In ActiveDocument.FormFields
ff.Range.Fields(1).Unlink
Next ff
If you want to execute the merge and then have the formfields in the
resulting document, the following code is the vba equivalent of that in the
KB article:
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="ffhere", Wrap:=wdFindContinue,
Forward:=True) = True
ActiveDocument.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
Loop
End With
ActiveDocument.Protect wdAllowOnlyFormFields
It assumes that the place where the formfields are to be entered is marked
with ffhere
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
"AnnP" <anon...@discussions.microsoft.com> wrote in message
news:034f01c39f33$872d0950$a401...@phx.gbl...
Thank you for your prompt response. Your solution worked
well. The only thing I had to do was undo the text
wrapping in the code after I cut and pasted.
Ann
>.
>