Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Suki Suki is offline
external usenet poster
 
Posts: 3
Default Mail merge question

Does anybody know how to mail merge with a Word document that has been
protected for forms?

Thanks.
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Mail merge question

The two features in Word are mutually exclusive, principally because each
bookmark in a document must be unique. You can of course unprotect the
document and then execute the merge, but of course, the formfields will not
be retained in the merged document.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Suki" wrote in message
...
Does anybody know how to mail merge with a Word document that has been
protected for forms?

Thanks.



  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Patty Patty is offline
external usenet poster
 
Posts: 31
Default Mail merge question

Hey Suki -
I just did this! It took a bit of research to find all the necessary
pieces, but it works. :-)
You will need to create a macro that does the following things:
- unlock and relock the document
- circumvent the form field/mail merge bug
- do the merge
- lock the resultant form document

I cut and pasted this soluction using a variety of sources. Below the
resultant macro. Hopefully it will help you.

Patty

Macro:
Private Sub Document_Open()
'merge.txt Macro
Application.Visible = True
Application.WindowState = wdWindowStateMinimize
Application.DisplayAlerts = wdAlertsNone

Dim fFieldText() As String
Dim iCount As Integer
Dim fField As FormField

docname = ActiveDocument.Name
datapath = "c:\xxxxxx\"

' Because the document contains form fields,
' it is protected, so unprotect document.
If ActiveDocument.ProtectionType wdNoProtection Then
ActiveDocument.Unprotect
End If

ActiveDocument.MailMerge.OpenDataSource Name:=datapath & _
Left(docname, Len(docname) - 4) & ".txt", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="SELECT * FROM
'Data'", SQLStatement1:=""

' Loop through all text form fields
' in the main mail merge document.
For Each aField In ActiveDocument.FormFields

' If the form field is a text form field...
If aField.Type = wdFieldFormTextInput Then
' Redim array to hold contents of text field.
ReDim Preserve fFieldText(1, iCount + 1)
' Place content and name of field into array.
fFieldText(0, iCount) = aField.Result
fFieldText(1, iCount) = aField.Name
' Select the form field.
aField.Select
' Replace it with placeholder text.
Selection.TypeText "" & fFieldText(1, iCount) & "PlaceHolder"
' Increment icount
iCount = iCount + 1
End If
Next aField

With ActiveDocument.MailMerge

.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
.DataSource.FirstRecord = wdDefaultFirstRecord
.DataSource.LastRecord = wdDefaultLastRecord
.Execute (True)

' Find and Replace placeholders with form fields.
doFindReplace iCount, fField, fFieldText()

' Protect the merged document
ActiveDocument.Protect Password:="", NoReset:=True, _
Type:=wdAllowOnlyFormFields

End With

Application.Documents("MYDOC.doc").Close
(Word.WdSaveOptions.wdDoNotSaveChanges)


End Sub
Sub doFindReplace(iCount As Integer, fField As FormField, _
fFieldText() As String)

' Go to top of document.
Selection.HomeKey Unit:=wdStory

' Initialize Find.
Selection.Find.ClearFormatting

With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

' Loop form fields count.
For i = 0 To iCount

' Execute the find.
Do While .Execute(FindText:="" & fFieldText(1, i) _
& "PlaceHolder") = True

' Replace the placeholder with the form field.
Set fField = Selection.FormFields.Add _
(Range:=Selection.Range, Type:=wdFieldFormTextInput)

' Restore form field contents and bookmark name.
fField.Result = fFieldText(0, i)
fField.Name = fFieldText(1, i)
Loop

' Go to top of document for next find.
Selection.HomeKey Unit:=wdStory

Next
End With

End Sub


"Suki" wrote:

Does anybody know how to mail merge with a Word document that has been
protected for forms?

Thanks.

  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Bex Bex is offline
external usenet poster
 
Posts: 1
Default Mail merge question

Patty,

I ireally want to use your macro but my VB's not up to much and it gets
stuck at...

ActiveDocument.MailMerge.OpenDataSource Name:=datapath & _
Left(docname, Len(docname) - 4) & ".txt", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="SELECT *
FROM "
'Data'", SQLStatement1:=""

I'm trying to send a document with form fields as an attachment via e
mail to multiple recipients. The data source is an access database. Do
I need to point the above at my database data source?

Thanks in advance,

Bex

  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Mail merge question

See the article "Mail Merge to E-mail with Attachments" at

http://word.mvps.org/FAQs/MailMerge/...ttachments.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Bex" wrote in message
ups.com...
Patty,

I ireally want to use your macro but my VB's not up to much and it gets
stuck at...

ActiveDocument.MailMerge.OpenDataSource Name:=datapath & _
Left(docname, Len(docname) - 4) & ".txt", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="SELECT *
FROM "
'Data'", SQLStatement1:=""

I'm trying to send a document with form fields as an attachment via e
mail to multiple recipients. The data source is an access database. Do
I need to point the above at my database data source?

Thanks in advance,

Bex





  #6   Report Post  
Posted to microsoft.public.word.mailmerge.fields
rgaye rgaye is offline
external usenet poster
 
Posts: 1
Default Mail merge question

Hi Suki

I wrestled with this for a couple of days and finally used this simple work
around.

I create my merge form in the header and/or footer area of the document.
Before creating my form and adding any merge fields (or copy them from an
existing form), open a blank document, go into File, Page Setup and adjust
your margins, header and footer to encompass the bulk of the printable page
area or size and area you need for the merge data. Open Headers and create
the new mail merge form in the normal manner or copy the existing form into
the header or footer.

I leave a couple of lines or more between the header and footer when using
both, at a logical break point somewhere in the middle of the form. If you
work with this a bit you'll develop a feel for it from form to form. It
works as an area to separate the header and footer and for the cursor to set
on when the document is opened, but all the mail merge fields and form
structure that are in the header/footer, are grayed out.

This doesn't lock the document but effectively keeps it from accidental
deletions or changes, which is what I am usually most worried about. The
user must be in the View, Headers menu to make changes... which can't usually
be passed off as an accident if they screw it up.

There may be a few instances where this won't work very well, cant think of
too many though. Once your merge fields are aligned and formatted correctly,
it does work very well for completing preprinted forms from a spreadsheet.

All features of mail merge and formatting work in the header/footer that I
have tried. I am using Office 2003, usually Word and Excel together.

Hope this helps.

RGaye


"Suki" wrote:

Does anybody know how to mail merge with a Word document that has been
protected for forms?

Thanks.

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
NO CODE - mail merge to Outlook with attachment with CC BrianH Mailmerge 1 February 10th 10 03:53 PM
Mail merge in Word from Outlook Catagories stephen Mailmerge 7 December 11th 06 07:48 PM
Heavy Mail Merge Application Atul Mailmerge 1 August 17th 06 02:37 PM
mail merge with word 2003 ken sunshine New Users 5 March 23rd 06 06:01 PM
mail merge with attachments AS Mailmerge 5 April 9th 05 09:49 AM


All times are GMT +1. The time now is 09:49 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"