View Single Post
 
Old 10-05-2018, 04:48 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Loosely based on http://www.gmayor.com/individual_merge_letters.htm, try the following, which assumes that the bookmarks mark the ends of the files and that there is no bookmark at the end or the start of the document.

Change the value of strPath to a folder that exists,

Code:
Sub Splitter()
' 'Graham Mayor - http://www.gmayor.com - Last updated - 05 Oct 2018
' to split a document to separate PDF files by bookmarks
Dim strMask As String
Dim lngDocs As Long
Dim lngCount As Long
Dim strName As String
Dim oDoc As Document
Dim oRng As Range

Const strPath As String = "E:\Path\Forum\Backup\"
    Set oDoc = ActiveDocument
    oDoc.Save
    lngDocs = oDoc.Bookmarks.Count + 1
    strMask = "ddMMyy"
    lngCount = 1
    While lngCount <= lngDocs
        Set oRng = oDoc.Range
        If lngCount < lngDocs Then
            oRng.End = oDoc.Bookmarks(1).Range.End
            oDoc.Bookmarks(1).Delete
        End If

        strName = Format(Date, strMask) _
                  & " " & LTrim$(Str$(lngCount)) & ".pdf"
        oRng.ExportAsFixedFormat _
                OutputFileName:=strPath & strName, _
                ExportFormat:=wdExportFormatPDF, _
                OptimizeFor:=wdExportOptimizeForPrint, _
                CreateBookmarks:=wdExportCreateWordBookmarks, _
                DocStructureTags:=True, _
                BitmapMissingFonts:=True
        lngCount = lngCount + 1
        oRng.Text = ""
    Wend
    oDoc.Close wdDoNotSaveChanges
End Sub
__________________
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