Results 1 to 14 of 14
  1. #1
    New Lounger
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Save Catalogue/Directory Mailmerge output as Individual PDFs

    Hi All,
    I've been reading the above tutorial which has being a great help, my appreciation to the author.

    I'm just stuck on one thing, I've managed to get the content of the letter incorporated into the coding.

    Our company has it's logo in the header and footer of all letters sent.
    Where and how do I include these on each page of the letter regardless if the table extend over a few pages?

    thank you!!!

  2. #2
    New Lounger
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think I figure it out reading some other post.
    I just add the header and footer after I've merged the data.

    Now just need some help saving each letter with different person's name as a PDF file.

    I found the following code in a different post, which does it by page numbers.

    How can I edit it so that it'll check the person's name and then use that as a start of a new page and find the end/last page with my signture on it or page break?
    Thank you!!!

    Sub Demo()
    Dim i As Long, StrNm As String
    StrNm = "C:\Monthly\Receipt No -"
    With ActiveDocument
    For i = 1 To .ComputeStatistics(wdStatisticPages)
    .ExportAsFixedFormat OutputFileName:=StrNm & i, ExportFormat:=wdExportFormatPDF, _
    From:=i, To:=i, OptimizeFor:=wdExportOptimizeForPrint
    Next
    End With
    End Sub
    Last edited by huntresslove; 2014-01-05 at 21:34.

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,892
    Thanks
    0
    Thanked 188 Times in 172 Posts
    You could simply add the header/footer content to the mailmerge main document, before the merge.

    Unless the person's name occupies the same pre-determined position in each letter (e.g. 2nd word of paragraph 3), it would be difficult to code a macro to save the file with the names.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    New Lounger
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Paul,

    The person's name is always on the 2nd line of each letter, so it starts with date, then the person's name.
    Is it possible to code it with what ever is on the 2nd line?

    I was also reading the document can be split with page breaks, but unsure how to make it all work.

    cheers!
    Li

  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,892
    Thanks
    0
    Thanked 188 Times in 172 Posts
    Lines are a fluid concept in Word and can vary with printer driver. What I'd need to know is whether that line is in the first or second paragraph on the page and whether the lines within those paragraphs (if they're multi-lined) are terminated by line breaks.

    As for the use of page breaks, the field code inserts manual page breaks which can be used as the document delimiters, rather than relying on pages, per se, since a long letter might span more than one page.

    Since you have header/footer content, some extra code would be required to replicate that in each of the output documents also.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  6. #6
    New Lounger
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, I see, then the names are always the first 2 words in the 2nd pargraph of each page.

    There's a line between the date and the name does that also count as a pargraph, if so then it's the 3rd.

    I've attached the top of the letter where the name is, as I'm not sure what kind of line/mark the arrow is.

    (BTW the logo, compnay name and slogan is all the header)

    thank you!
    Attached Images Attached Images
    Last edited by huntresslove; 2014-01-06 at 00:09.

  7. #7
    New Lounger
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Save as PDF file

    Hi All,

    I've being reading Graham Mayor site and managed to get my mail merge to print separate document for each letter.

    But I still need these document in PDF format and I'm having trouble figuring out which line of code to replace "ExportAsFixedFormat OutputFileName:=sName, ExportFormat:=wdExportFormatPDF," to make it work. I was hoping someone can give me a hand with modifying the code below:

    Code:
    Sub SplitMergeLetter()
    ' splitter Macro modified to save individual letters with
    ' information from data source. The filename data must be added to
    ' the top of the merge letter - see web article.
    Dim sName As String
    Dim docName As String
    Dim Letters As String
    Dim Counter As Long
    Dim oDoc As Document
    Dim oNewDoc As Document
    Set oDoc = ActiveDocument
    oDoc.Save
    Selection.EndKey Unit:=wdStory
    Letters = Selection.Information(wdActiveEndSectionNumber)
    Selection.HomeKey Unit:=wdStory
    Counter = 1
    While Counter < Letters
    Application.ScreenUpdating = False
    With Selection
    .HomeKey Unit:=wdStory
    .EndKey Unit:=wdLine, Extend:=wdExtend
    .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    End With
    sName = Selection
    docName = "C:\Users\PRLZMB\SDF\" & sName & ".doc"
    oDoc.Sections.First.Range.Cut
    Set oNewDoc = Documents.Add
    'Documents are based on the Normal template
    'To use an alternative template follow the link.
    With Selection
    .Paste
    .HomeKey Unit:=wdStory
    .MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
    .Delete
    End With
    oNewDoc.SaveAs FileName:=docName, _
    FileFormat:=wdFormatDocument, _
    AddToRecentFiles:=False
    ActiveWindow.Close
    Counter = Counter + 1
    Application.ScreenUpdating = True
    Wend
    oDoc.Close wdDoNotSaveChanges
    End Sub
    Thank you in advance!!!

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,892
    Thanks
    0
    Thanked 188 Times in 172 Posts
    Assuming your names do indeed constitute the 2nd paragraph (it looks like the 3rd in your thumbnail), the following should work:
    Code:
    Sub Demo()
    Application.ScreenUpdating = False
    Dim StrPages As String, StrPath As String, StrFile As String, StrNms As String
    Dim i As Long, iLo As Long, iHi As Long
    With ActiveDocument
      'Get the output path
      StrPath = .Path & "\"
      'Get the name for the first output document
      StrNms = Replace(.Paragraphs(2).Range.Text, Chr(11), vbNullString)
      'Initialize the counter
      i = 1
      'Find all the manual page breaks
      With .Range
        With .Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Text = "^m"
          .Replacement.Text = ""
          .Forward = True
          .Wrap = wdFindStop
          .Execute
        End With
        Do While .Find.Found
          'Add the page #s to the pages list
          StrPages = StrPages & i & vbTab & .Duplicate.Information(wdActiveEndPageNumber) & vbCr
          i = .Duplicate.Information(wdActiveEndPageNumber) + 1
          'Add the names for the additional documents to the output names list
          StrNms = StrNms & Replace(.Duplicate.Paragraphs.Last.Next.Next.Range.Text, Chr(11), vbNullString)
          .Collapse wdCollapseEnd
          .Find.Execute
        Loop
      End With
      'Add the last page(s) to the pages list
      StrPages = StrPages & i & vbTab & .Characters.Last.Information(wdActiveEndPageNumber)
      For i = 0 To UBound(Split(StrPages, vbCr))
        StrFile = StrPath & Split(StrNms, vbCr)(i) & ".pdf"
        iLo = Split(Split(StrPages, vbCr)(i), vbTab)(0)
        iHi = Split(Split(StrPages, vbCr)(i), vbTab)(1)
        'save to PDF
        .ExportAsFixedFormat OutputFileName:=StrFile, ExportFormat:=wdExportFormatPDF, _
          OptimizeFor:=wdExportOptimizeForPrint, Item:=wdExportDocumentContent, From:=iLo, To:=iHi
      Next
    End With
    Application.ScreenUpdating = True
    End Sub
    Last edited by macropod; 2014-01-08 at 22:10. Reason: Minor code tweak
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #9
    New Lounger
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Paul,

    thank you, will give it a go!

  10. #10
    New Lounger
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Extra blank pages

    Hi Paul,
    I tried the code you posted, but couldn't get it to work.

    I've managed to get a different code below to do what I want with only 1 problem.

    Becuase the letters are created using section breaks in main letter merge, it creates an extra blank page per letter.

    I've inserted the code:
    Code:
    oNewDoc.Sections(2).PageSetup.SectionStart = wdSectionContinuous
    So that it gets rid of the section beak in the new letter hence extra page, but only seem to work for the first one and not the rest, do I need to loop it somehow?

    The full code for the process below:

    Code:
    Sub SplitMergeLetter()
    ' splitter Macro modified to save individual letters with
    ' information from data source. The filename data must be added to
    ' the top of the merge letter - see web article.
    Dim sName As String
    Dim DocName As String
    Dim Letters As String
    Dim Counter As Long
    Dim oDoc As Document
    Dim oNewDoc As Document
    Set oDoc = ActiveDocument
    oDoc.Save
    Selection.EndKey Unit:=wdStory
    Letters = Selection.Information(wdActiveEndSectionNumber)
    Selection.HomeKey Unit:=wdStory
    Counter = 1
    While Counter < Letters
    Application.ScreenUpdating = False
    With Selection
    .HomeKey Unit:=wdStory
    .EndKey Unit:=wdLine, Extend:=wdExtend
    .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    End With
    sName = Selection
    DocName = "G:\test\" & sName & ".pdf"
    oDoc.Sections.First.Range.Cut
    Set oNewDoc = Documents.Add
    'Documents are based on the Normal template
    'To use an alternative template follow the link.
    With Selection
    .Paste
    .HomeKey Unit:=wdStory
    .MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
    .Delete
    End With
    oNewDoc.Sections(2).PageSetup.SectionStart = wdSectionContinuous
    oNewDoc.SaveAs FileName:=DocName, _
    FileFormat:=wdFormatPDF
    oNewDoc.Close wdDoNotSaveChanges
    Counter = Counter + 1
    Application.ScreenUpdating = True
    Wend
    oDoc.Close wdDoNotSaveChanges
    End Sub
    Thank you!!!
    Last edited by huntresslove; 2014-01-13 at 21:12.

  11. #11
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,892
    Thanks
    0
    Thanked 188 Times in 172 Posts
    It would have been helpful if you'd indicated what you're using for the document delimiters from the outset, especially given that the title you originally gave the thread refers to a process that doesn't ordinarily use Section breaks... Had I known that, I wouldn't have offered the solution I gave. A process that uses Section breaks is in some respects much easier to implement. However, I'm travelling at the moment and don't really have time to focus on that. You will, however, find some code you can adapt at: http://www.gmayor.com/individual_merge_letters.htm
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  12. #12
    New Lounger
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Paul,
    Sorry about the inconvenience, I didn't use this code to start with.
    Since I was not able to incorporate printing to PDF in your original mail merge tutorial I went looking for a different solution.
    So now I use that for the mail merge and do a 2nd step of changing all the break pages to section breaks so I could run above macro.

    Thank you for your response!

  13. #13
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,892
    Thanks
    0
    Thanked 188 Times in 172 Posts
    Quote Originally Posted by huntresslove View Post
    Since I was not able to incorporate printing to PDF in your original mail merge tutorial I went looking for a different solution.
    So now I use that for the mail merge and do a 2nd step of changing all the break pages to section breaks so I could run above macro.
    But if you hadn't changed the page breaks that the tutorial uses to Section breaks, the Sections problem would never have arisen...
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  14. #14
    New Lounger
    Join Date
    Jan 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh I see! thank you for your feedback Paul.
    I'll have another crack at the code you posted above and see why it's not working with my document.

    Cheers!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •