Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 

Tags
pdf conversion, vba code, word macro



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:32 AM.


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