Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2022, 12:46 PM
MatuteV33 MatuteV33 is offline Split Word into pdf every X pages Windows 10 Split Word into pdf every X pages Office 2016
Novice
Split Word into pdf every X pages
 
Join Date: Jan 2022
Posts: 2
MatuteV33 is on a distinguished road
Default Split Word into pdf every X pages

Hi!



I have the below code that splits a word into individual pdfs by each page, creating a folder and dropping the file in there. The thing is that I would like to be able to select every X amount of pages instead of being one pdf per page. Any suggestions?

Code:
Sub Merge_To_Individual_Files()
' Sourced from: https://www.msofficeforums.com/mail-...ps-tricks.html
Application.ScreenUpdating = False
Dim StrFolder As String, StrName As String, MainDoc As Document, i As Long, j As Long
Const StrNoChr As String = """*./\:?|"
Set MainDoc = ActiveDocument
With MainDoc
  StrFolder = .Path & "\"
  With .MailMerge
    .Destination = wdSendToNewDocument
    .SuppressBlankLines = True
    On Error Resume Next
    For i = 1 To .DataSource.RecordCount
      With .DataSource
        .FirstRecord = i
        .LastRecord = i
        .ActiveRecord = i
        If Trim(.DataFields("X")) = "" Then Exit For
        'StrFolder = .DataFields("Folder") & ""
        StrName = .DataFields("X") & "_" & .DataFields("X")
      End With
      On Error GoTo NextRecord
      .Execute Pause:=False
      For j = 1 To Len(StrNoChr)
        StrName = Replace(StrName, Mid(StrNoChr, j, 1), "_")
      Next
      StrName = Trim(StrName)
      StrFolderRowName = StrFolder & StrName
      If Dir(StrFolderRowName, vbDirectory) = "" Then MkDir StrFolderRowName
      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:=StrFolderRowName & "" & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
        .Close SaveChanges:=False
      End With
NextRecord:
    Next i
  End With
End With
Application.ScreenUpdating = True
End Sub
Thanks,

Last edited by macropod; 01-16-2022 at 01:41 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 01-16-2022, 01:47 PM
macropod's Avatar
macropod macropod is offline Split Word into pdf every X pages Windows 10 Split Word into pdf every X pages Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The code you posted does not split a Word document "into individual pdfs by each page". It processes a mailmerge creating a new file for each record. The number of pages for each record depends entirely on what's in the mailmerge main document, be that one page or one hundred.

The code for splitting a document is found under the Split Merged Output to Separate Documents topic in the same Mailmerge Tips & Tricks 'Sticky' thread you got your posted code from: https://www.msofficeforums.com/mail-...ps-tricks.html. That code allows you to specify how many pages each new document should contain.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-16-2022, 01:53 PM
MatuteV33 MatuteV33 is offline Split Word into pdf every X pages Windows 10 Split Word into pdf every X pages Office 2016
Novice
Split Word into pdf every X pages
 
Join Date: Jan 2022
Posts: 2
MatuteV33 is on a distinguished road
Default

Oh, my bad. Thought it did something completely different. I just tested what you said and it actually does what I needed.

Thanks!!

Quote:
Originally Posted by macropod View Post
The code you posted does not split a Word document "into individual pdfs by each page". It processes a mailmerge creating a new file for each record. The number of pages for each record depends entirely on what's in the mailmerge main document, be that one page or one hundred.

The code for splitting a document is found under the Split Merged Output to Separate Documents topic in the same Mailmerge Tips & Tricks 'Sticky' thread you got your posted code from: https://www.msofficeforums.com/mail-...ps-tricks.html. That code allows you to specify how many pages each new document should contain.
Reply With Quote
Reply

Tags
pdf conversion, vba code, word macro

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Split Word into pdf every X pages Split a Word document in "n" pages dlinto Word VBA 1 03-24-2021 02:57 PM
Why won't table split across pages? lynn0712 Word Tables 5 12-16-2019 02:10 PM
Split pages rom A3 to A4 dominbdg Word 1 07-22-2019 08:36 AM
Split Word into pdf every X pages workseet with Tables for VLOOKUP formulas needs to be split into 3 pages innkeeper9 Excel 4 10-05-2016 01:45 PM
Split Word into pdf every X pages Automatically split Mail Merge based on number of pages SaneMan Mail Merge 1 12-03-2011 01:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:56 AM.


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