#1
|
|||
|
|||
Mail Merge with Merged File Name in Footer
We often have a need to create cover pages for technical documents submitted to clients. Mail Merge to a PDF seems to be the simplest solution. I've read several posts on the subject: But ended up using a AddIn from "Greg Mayor" (http://www.gmayor.com/individual_merge_letters.htm) as it has provided me the a "best fit" solution. The AddIn permits me to "...run a macro before saving the documents..." with a caveat that... Quote:
Code:
Sub FormatTM(oDoc As Document) Dim oRng As Range Set oRng = oDoc.Range With oRng.Find Do While .Execute(FindText:=ChrW(174)) With oRng.Font .name = "Segoe UI" .Superscript = True End With Loop End With End Sub Code:
Sub FooterTx()(oDoc As Document) Dim i As Long, Source As Document, Target As Document, Letter As Range Dim fname As Range Set Source = ActiveDocument With Source For i = 1 To .Sections.Count Set fname = .Sections(i).Footers(wdHeaderFooterPrimary).Range fname.End = fname.End - 1 Set Letter = .Sections(i).Range Letter.End = Letter.End - 1 Set Target = Documents.Add With Target .Range.FormattedText = Letter.FormattedText .Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = "" .SaveAs FileName:=fname.Text & " - Contributions", FileFormat:=wdFormatPDF .Close wdDoNotSaveChanges End With Next i End With End Sub Doug Robbins code by itself works for me, but not in the Addit. Anyone's help would be appreciated. |
#2
|
||||
|
||||
While my friend Greg Maxey and I have similar initials, we are not the same person and it is he who is 'Greg'.
The macro Doug supplied is not compatible with the add-in process as even if it was, the macro runs before the document filename is created and thus before it is saved so it cannot reflect the name of that document in its footer. If the aim is to add the filename to the footer then you can get the name of the document (not the PDF file) with Code:
Sub FooterTx(oDoc As Document) Dim i As Long Dim fname As Range With oDoc Set fname = .Sections(1).Footers(wdHeaderFooterPrimary).Range fname.End = fname.End - 1 fname.Collapse 0 fname.Fields.Add fname, wdFieldFileName, " \p", False End With End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
You might be interested in the Send Mailmerge Output to Individual Files topic in the Mailmerge Tips & Tricks 'Sticky' thread: https://www.msofficeforums.com/mail-...ps-tricks.html. The code there allows you to nominate any suitable data field for the file name and, if you follow the instructions in the notes below that topic, the process is entirely transparent to the user. As for having the filename in the footer, all you need do is add a FILENAME field to the mailmerge main document's footer.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Quote:
Is there anyway, using your addin, to merge the output with an existing PDF? Quote:
I did read your sticky on Mailmerge and again, it was late at night, and my brain was getting lazy. |
#5
|
||||
|
||||
My reference to the FILENAME field concerns how my process would work, not Graham's addin.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Quote:
I noticed that when the <<filename>> field is in the body of the mail merge document, the macro you provided, does it's job on the output word document. I also noted that if the <<filename>> is placed in the footer, the macro does NOT add the file name to the output word document. In both cases the <<filename>> doesn't make it to the PDF as you mentioned. |
#7
|
|||
|
|||
Quote:
|
#8
|
||||
|
||||
Quote:
The macro inserts a filename field in the footer of the created documents. Any pre-existing filename field in the footer from the merge document will not reflect the names of the documents after the merge and should be removed before running the merge. The process assumes that you are using the current version of the add-in and that you have entered the macro name on the macro tab.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#9
|
||||
|
||||
I've now added a line of VBA code to the example there to populate the footer prgrammatically.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
Quote:
I think you're talking about the below code, which I think is new under the heading " Send Mailmerge Output to Individual Files"? Code:
With ActiveDocument 'Add the name to the footer '.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertBefore StrName .SaveAs FileName:=StrFolder & StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False ' and/or: .SaveAs FileName:=StrFolder & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False .Close SaveChanges:=False End With |
#11
|
||||
|
||||
Only:
Code:
'Add the name to the footer '.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertBefore StrName
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
showing mail merge all in one file | lezawang | Mail Merge | 3 | 05-24-2018 03:10 PM |
Log file for mail merge | neilclelland | Mail Merge | 7 | 12-08-2016 03:08 PM |
some records disappear after emailing mail merged file | Dr Ennui | Mail Merge | 1 | 06-10-2015 04:17 PM |
Mail Merge is Deleting objects in my header and footer during the merge | bgranzow | Mail Merge | 9 | 06-05-2015 05:03 AM |
how do i ad a specific pdf file to a mail merge? | mseibel | Mail Merge | 1 | 08-28-2012 07:53 PM |