Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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, 11 views)
File Type: xlsx merge_data.xlsx (9.7 KB, 8 views)
Reply With Quote
 

Tags
merge excel pdf



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

All times are GMT -7. The time now is 08:04 PM.


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