Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Saving a mail merged document using the value from a datafield
Hi,
I am running a mail merge to a new document. The template is one page, and I have some code to pull each page from the merged document and save it as its own new file. So, right now, it ends up being MergeResult1.doc, MergeResult2.doc, MergeResult3.doc, etc... What I want to do is save each file using one of the datafield values (employee ID). In this case, it would look like this: employee_12345.doc, employee_67890.doc, employee_98765.doc, etc. Right now the code saves the doc using a doc counter, but I want to have it pull the value from the employee ID datafield and add it to the filename string. I know this is simple for someone out there. Can you help me out? ~ Sean Here's my code Sub SaveAllSubDocs(ByRef doc As Word.Document) Dim subdoc As Word.Subdocument Dim newdoc As Word.Document Dim docCounter As Long docCounter = 1 'Must be in MasterView to work with 'Subdocs as separate files doc.ActiveWindow.View = wdMasterView For Each subdoc In doc.Subdocuments Set newdoc = subdoc.Open 'Remove NextPage section breaks 'originating from mailmerge RemoveAllSectionBreaks newdoc With newdoc ..SaveAs FileName:="MergeResult" & CStr(docCounter) ..Close End With docCounter = docCounter + 1 Next subdoc End Sub |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Saving a mail merged document using the value from a datafield
See http://www.gmayor.com/individual_merge_letters.htm
-- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Biz Analyst wrote: Hi, I am running a mail merge to a new document. The template is one page, and I have some code to pull each page from the merged document and save it as its own new file. So, right now, it ends up being MergeResult1.doc, MergeResult2.doc, MergeResult3.doc, etc... What I want to do is save each file using one of the datafield values (employee ID). In this case, it would look like this: employee_12345.doc, employee_67890.doc, employee_98765.doc, etc. Right now the code saves the doc using a doc counter, but I want to have it pull the value from the employee ID datafield and add it to the filename string. I know this is simple for someone out there. Can you help me out? ~ Sean Here's my code Sub SaveAllSubDocs(ByRef doc As Word.Document) Dim subdoc As Word.Subdocument Dim newdoc As Word.Document Dim docCounter As Long docCounter = 1 'Must be in MasterView to work with 'Subdocs as separate files doc.ActiveWindow.View = wdMasterView For Each subdoc In doc.Subdocuments Set newdoc = subdoc.Open 'Remove NextPage section breaks 'originating from mailmerge RemoveAllSectionBreaks newdoc With newdoc .SaveAs FileName:="MergeResult" & CStr(docCounter) .Close End With docCounter = docCounter + 1 Next subdoc End Sub |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Saving mail merged letters as seperate documents | Microsoft Word Help | |||
Problem Saving a Merged Document in Word 2003 | Mailmerge | |||
E-mail merged document with replies going to different e-mail addr | Mailmerge | |||
How do I attach a WORD document to mail-merged e-mail? | Mailmerge | |||
How do I email a mail merged document? | Mailmerge |