Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / October 2003

Tip: Looking for answers? Try searching our database.

Text Form Fields Are Not Retained During Mail Merge

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AnnP - 30 Oct 2003 23:16 GMT
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 - 31 Oct 2003 09:59 GMT
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
> When I do a mail merge the text form fields disappear.  I
> looked at the knowledge base article 146644 that describes
[quoted text clipped - 33 lines]
> merged document into separate documents and that worked
> fine.
AnnP - 31 Oct 2003 21:29 GMT
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

>-----Original Message-----
>Hi Ann,
[quoted text clipped - 73 lines]
>
>.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.