Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Text Form Fields Are Not Retained During Mail Merge

1 view
Skip to first unread message

AnnP

unread,
Oct 30, 2003, 5:16:55 PM10/30/03
to
When I do a mail merge the text form fields disappear. I
looked at the knowledge base article 146644 that describes
this known problem. It gives an example of a fix but I
can't get it to work. I am using Word2000. Here is the
code I pasted into a macro and attempted to run on the
merged document. When I debug it highlights
StartOfDocument and I get the error "compile error: sub or
function not defined"

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.


Doug Robbins - Word MVP

unread,
Oct 31, 2003, 3:59:05 AM10/31/03
to
Hi Ann,

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...

AnnP

unread,
Oct 31, 2003, 3:29:49 PM10/31/03
to
Doug,

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

>.
>

0 new messages