Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-04-2021, 02:23 AM
ales.jamsek ales.jamsek is offline Merge group by key and split to individual pdf files Windows 10 Merge group by key and split to individual pdf files Office 2016
Novice
Merge group by key and split to individual pdf files
 
Join Date: Jan 2021
Posts: 4
ales.jamsek is on a distinguished road
Default Merge group by key and split to individual pdf files

Hello everyone!



With the help from few posts from these forums I have managed to almost completely solve my problem which is: I want to create certificates for users that attended different classes during the year and where each user's certificate would list all the classes he attended. I have data stored in attached xlsx file. Fields to group and merge data are in my main document (merge_main.docx).

If I just run normal mail-merge in word, merged document gets created just fine, each page has certificate for one user and all classes he attended are listed.

But then I added to the main document following macro to separate merged document to individual pdf files:

Code:
Sub Merge_To_Individual_Files()
'
' Merges one record at a time to the "potrdila" sub-folder

Application.ScreenUpdating = False
Dim StrFolder As String, StrName As String, MainDoc As Document, i As Long, j As Long
Set MainDoc = ActiveDocument
With MainDoc
  StrFolder = .Path & "\potrdila\"
  With CreateObject("Scripting.FileSystemObject")
    If Not .FolderExists(StrFolder) Then .CreateFolder StrFolder
  End With
  For i = 1 To .MailMerge.DataSource.RecordCount
    With .MailMerge
      .Destination = wdSendToNewDocument
      .SuppressBlankLines = True
      With .DataSource
        .FirstRecord = i
        .LastRecord = i
        .ActiveRecord = i
        StrName = .DataFields("User")
      End With
      .Execute Pause:=False
    End With
    With ActiveDocument
      .SaveAs2 FileName:=StrFolder & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
      .Close SaveChanges:=False
    End With
  Next i
End With
Application.ScreenUpdating = True

End Sub
Pdf files are created fine, but the problem is, that for each user just the first class he attended is listed. Where did I go wrong?

Thanks.
Attached Files
File Type: docx merge_main.docx (29.8 KB, 2 views)
File Type: xlsx merge_data.xlsx (9.7 KB, 1 views)
Reply With Quote
  #2  
Old 01-04-2021, 02:53 AM
gmayor's Avatar
gmayor gmayor is offline Merge group by key and split to individual pdf files Windows 10 Merge group by key and split to individual pdf files Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,344
gmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to all
Default

This is a many to one mail merge - see Merge Many To One and the attached modified merge document and resulting files.
Attached Files
File Type: zip TestMerge.zip (81.4 KB, 2 views)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 01-04-2021, 05:41 AM
ales.jamsek ales.jamsek is offline Merge group by key and split to individual pdf files Windows 10 Merge group by key and split to individual pdf files Office 2016
Novice
Merge group by key and split to individual pdf files
 
Join Date: Jan 2021
Posts: 4
ales.jamsek is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
This is a many to one mail merge - see Merge Many To One and the attached modified merge document and resulting files.
Thank you very much, your add-in helped a lot!
Reply With Quote
  #4  
Old 01-21-2021, 05:24 AM
ales.jamsek ales.jamsek is offline Merge group by key and split to individual pdf files Windows 10 Merge group by key and split to individual pdf files Office 2016
Novice
Merge group by key and split to individual pdf files
 
Join Date: Jan 2021
Posts: 4
ales.jamsek is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
This is a many to one mail merge - see Merge Many To One and the attached modified merge document and resulting files.
Just one more thing: I've tried creating PDF files with PDFcreator (v. 2.5.2) and your Many to One addin (v. 17.7) and when it started merging process it looks like it stopped at creation of the first PDF file with following error:



Any advice with this? Thank you.
Reply With Quote
  #5  
Old 01-21-2021, 09:27 PM
gmayor's Avatar
gmayor gmayor is offline Merge group by key and split to individual pdf files Windows 10 Merge group by key and split to individual pdf files Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,344
gmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to all
Default

Ensure that PDF Creator is not set to automatically update. If you still have problems, contact me via my web site.
Unless you need the added security use the Office PDF option to create the files.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
merge excel pdf

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge group by key and split to individual pdf files Password protect individual files after merge merkyfitz Mail Merge 4 03-10-2020 03:08 PM
Merge group by key and split to individual pdf files Mail Merge - split merged documents and rename each split document based on text in header FuriousD Word VBA 1 05-12-2019 04:06 AM
Merge group by key and split to individual pdf files Mail merge to individual files, there's any kind of progress indicator eduzs Word VBA 3 08-31-2018 08:46 PM
Merge group by key and split to individual pdf files Saving group of individual e-mails gerryex Outlook 12 07-04-2016 12:45 PM
Merge group by key and split to individual pdf files Mail Merge To Individual PDF Files iamrickdeans Mail Merge 1 01-15-2014 12:46 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 07:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft