Mailmerge W/O Template with Macros

S

Snailspace

I have a Template Work Order that we created that runs a Macro
automatically when launched that forces the user to enter in 3 pieces
of data prior to completing the document to generate a bar code.

What I would like to do is a mail merge and prepopulate the template
prior to the users accessing it to reduce their data entry. This data
would consist of just general contact information and has nothing to
do with the macro data.

My question is this - Can I do a mail merge on the template? Or am I
going to have to remove the macro, save the documents and then reapply
it afterwards? I am going to have to do this for a lot of jobs so any
assistance would be greatly appreciated.

I also already have a macro installed that separates the mail merge to
individual documents for later review. I was thinking that would help
also.

Suggestions?

Version : Word 2003

Thanks!
Christine
 
D

Doug Robbins - Word MVP on news.microsoft.com

Can you provide more information about the work process? Where are the
users located? From where does the data come that you want to be used to
pre-populate the template? Would the users have access to that data source?



--
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, originally posted via msnews.microsoft.com
 
S

Snailspace

My users are located across multiple cities and the pre-populated
documents will be emailed to their office. I will be pulling reports
to complete the forms with general information like names and
addresses so the users will not have access to the data.

We are trying to make it easier for our people in the field to
complete their paperwork. But there are a few fields that they must
fill out themselves.

Thanks!

Christine
 
D

Doug Robbins - Word MVP on news.microsoft.com

If your data source is an Access Database, starting with a mailmerge main
document to which the datasource is attached and which contains formfields,
the following macro will produce individual documents for each record in the
datasource with each of those documents containing the formfields so that
they would be available for your users to complete their part of the data.

To make use of the macro, it is necessary to set a reference in the Visual
Basic Editor (Tools>References) to the Microsoft DAO 3.6 Object Library.

Sub MailMergewithFormFields()

Dim dSource As String

Dim qryStr As String

Dim mfCode As Range

Dim i As Long, j As Long

Dim db As DAO.Database

Dim rs As DAO.Recordset

With ActiveDocument

'Get the details of the datasource

With .MailMerge.DataSource

dSource = .Name

qryStr = .QueryString

End With

'Convert the MERGEFIELDS to DOCVARIABLE fields

For i = 1 To .Fields.Count

If .Fields(i).Type = wdFieldMergeField Then

Set mfCode = .Fields(i).code

mfCode = Replace(mfCode, "MERGEFIELD", "DOCVARIABLE")

End If

Next i

'Convert the Mail Merge Main document to a normal Word document

.MailMerge.MainDocumentType = wdNotAMergeDocument

End With

' Open the database

Set db = OpenDatabase(dSource)

' Retrieve the recordset

Set rs = db.OpenRecordset(qryStr)

With rs

' Move to the first record

.MoveFirst

j = 1

Do While Not .EOF

'Create variables in the document with the names and values of the
fields in each record

For i = 0 To .Fields.Count - 1

If .Fields(i).Value <> "" Then

ActiveDocument.Variables(.Fields(i).Name).Value =
..Fields(i).Value

End If

Next i

ActiveDocument.Fields.Update

ActiveDocument.SaveAs "C:\Test\MwithFF" & j

.MoveNext

j = j + 1

Loop

End With

rs.Close

db.Close

Set rs = Nothing

Set db = Nothing



End Sub


Here is another macro that executes the merge to a new document in which it
will reinstate the formfields to the relevant places in that document and
then split that document into individual documents, which it then protects
for filling in formfields.. It only works with TextInput type FormFields
however

Sub MergewithFormFields()

Dim i As Long
Dim Source As Document, Target As Document
Dim Letter As Range
With ActiveDocument
For i = .FormFields.Count To 1 Step -1
If .FormFields(i).Type = wdFieldFormTextInput Then
.FormFields(i).Range.Text = "FF" & i
End If
Next i
With .MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
End With
Selection.HomeKey wdStory
With Selection.Find
Do While .Execute(FindText:="FF[0-9]{1,}", Forward:=True, _
MatchWildcards:=True, Wrap:=wdFindStop, MatchCase:=True) = True
ActiveDocument.FormFields.Add Selection.Range, wdFieldFormTextInput
Loop
End With
Set Source = ActiveDocument
For i = 1 To Source.Sections.Count
Set Letter = Source.Sections(i).Range
Set Target = Documents.Add
Target.Range = Letter
Target.Sections(2).PageSetup.SectionStart = wdSectionContinuous
Target.Protect wdAllowOnlyFormFields
Target.SaveAs FileName:="Letter" & i
Target.Close
Next i

End Sub
--
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, originally posted via msnews.microsoft.com

My users are located across multiple cities and the pre-populated
documents will be emailed to their office. I will be pulling reports
to complete the forms with general information like names and
addresses so the users will not have access to the data.

We are trying to make it easier for our people in the field to
complete their paperwork. But there are a few fields that they must
fill out themselves.

Thanks!

Christine
 

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